Skip to content

Commit

Permalink
Update document for efx-grid v6.0.150
Browse files Browse the repository at this point in the history
  • Loading branch information
efx-grid committed Jul 18, 2024
1 parent 719e864 commit 9072710
Show file tree
Hide file tree
Showing 72 changed files with 8,820 additions and 7,621 deletions.
2 changes: 1 addition & 1 deletion index.html

Large diffs are not rendered by default.

212 changes: 99 additions & 113 deletions resources/elf-halo-dark.js

Large diffs are not rendered by default.

212 changes: 99 additions & 113 deletions resources/elf-halo-light.js

Large diffs are not rendered by default.

255 changes: 232 additions & 23 deletions template-100.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,238 @@
<h1 id="changing-formatter-at-runtime">Changing Formatter at Runtime</h1>
<p>Sometimes you might want to change a custom rendering at runtime. This can be achieved by using <code>setColumnFormatter</code> method.</p>
<blockquote>
<p>APIs for Grid and the <code>setColumnFormatter()</code> method description can be found <a href="#/apis/rt-grid/grid">here</a>.</p>
</blockquote>
<pre><code class="language-js">var grid = document.getElementsByTagName(&quot;efx-grid&quot;)[0];

// formatter can be a function
var formatter = function(e) {
var value = e.grid.getRowData(e.rowIndex)[e.field];
e.cell.setContent(value);
};
<h1 id="text-selection">Text Selection</h1>
<p>Text selection has 2 scopes. It&#39;s grid scope and column scope. The default value of text selection is disabled, but you can enable it. If you enable it, users can select text in scope.</p>
<ul>
<li>The grid scope can enable by set textSelect property to <code>true</code> in configuration of <a href="#/apis/rt-grid/grid">Grid</a></li>
<li>The column scope can enable by set textSelect property to <code>true</code> in configuration of <a href="#/apis/rt-grid/columndefinition">Columns</a></li>
</ul>
<h2 id="limitation-with-safari">Limitation with safari</h2>
<ul>
<li>When you use Text selection with <a href="#/extensions/tr-grid-row-dragging">Row Dragging</a>, Safari is unable to select text.</li>
<li>Safari is unable to listening pointer events such as clicks, hovers, and so on. When you use <a href="#/rendering/custom-formatter">Custom Formatter</a> in a cell, it looks like this example.</li>
</ul>
<h3 id="example">Example</h3>
<p>If you use Safari, try clicking the button in column <code>Market</code> from the sample below. You won&#39;t be able to receive the click event.</p>
<code-sandbox hash="647069a8"><pre><code class="language-html">&lt;efx-grid id=&quot;grid&quot;&gt;&lt;/efx-grid&gt;
</code></pre>
<pre><code class="language-javascript">import { halo } from &#39;./theme-loader.js&#39;; // This line is only required for demo purpose. It is not relevant for your application.
await halo(); // This line is only required for demo purpose. It is not relevant for your application.

/*
// or can be an object.
var formatter = {
binding: function(e) {
var value = e.grid.getRowData(e.rowIndex)[e.field];
e.cell.setContent(value);
/* ---------------------------------- Note ----------------------------------
DataGenerator, Formatters and extensions are exposed to global scope
in the bundle file to make it easier to create live examples.
Importing formatters and extensions is still required in your application.
Please see the document for further information.
---------------------------------------------------------------------------*/
var fields = [&quot;companyName&quot;, &quot;market&quot;];
var records = DataGenerator.generateRecords(fields, { numRows: 10 });
var buttonDisplay = {
binding: function (e) {
var cellData = e.cell;
var buttonContent = document.createElement(&quot;button&quot;);
var spanContent = document.createElement(&quot;span&quot;);
buttonContent.addEventListener(&quot;click&quot; , () =&gt; {
alert(e.data);
});
spanContent.textContent = `${e.data}`;
buttonContent.appendChild(spanContent);
cellData.setContent(buttonContent);
}
};
// or can be a predefined formatter
var formatter = SimpleLinkFormatter.create()
*/

function handleChangeFormatter() {
grid.api.setColumnFormatter(0 /* Column Index */, formatter);
var configObj = {
rowVirtualRendering: false,
textSelect : true,
columns: [
{name: &quot;Company&quot;, field: fields[0]},
{name: &quot;Market&quot;, field: fields[1], formatter: buttonDisplay , width: 120}
],
staticDataRows: records
};

var grid = document.getElementById(&quot;grid&quot;);
grid.config = configObj;
</code></pre>
</code-sandbox><h2 id="limitation-with-row-virtualization">Limitation with row virtualization</h2>
<p>Text selection with row virtualization cannot select all data in the grid.
In the example below, the grid has text selection enabled and uses row virtualization.
When you try to select and copy text from the grid and paste it into a text area, you will see that not all data from the grid is obtained.
This is because row virtualization render only the rows that is visible in the grid&#39;s viewport.
For example, if you have 50 rows of data, but the grid can only show the first 10 rows at a time, then when you try to select the text, it will only select the first 14 rows (10 rows + buffer rows).
If you want to know about row virtualization in more detail, you can refer to the <code>Understanding row virtualization</code> section in the <a href="#/rendering/custom-formatter">Custom Formatter</a> page.</p>
<h3 id="example-1">Example</h3>
<code-sandbox hash="8eaf24c0"><pre><code class="language-css">efx-grid {
height: 300px;
}
textarea {
height: 200px;
width: 100%;
}
</code></pre>
<pre><code class="language-html">&lt;efx-grid id=&quot;grid&quot;&gt;&lt;/efx-grid&gt;
&lt;hr&gt;
&lt;textarea placeholder=&quot;Paste text here&quot;&gt;&lt;/textarea&gt;
</code></pre>
<pre><code class="language-javascript">import { halo } from &#39;./theme-loader.js&#39;; // This line is only required for demo purpose. It is not relevant for your application.
await halo(); // This line is only required for demo purpose. It is not relevant for your application.

/* ---------------------------------- Note ----------------------------------
DataGenerator, Formatters and extensions are exposed to global scope
in the bundle file to make it easier to create live examples.
Importing formatters and extensions is still required in your application.
Please see the document for further information.
---------------------------------------------------------------------------*/
var fields = [
&quot;id&quot;,
&quot;companyName&quot;,
&quot;market&quot;,
&quot;CF_LAST&quot;,
&quot;CF_NETCHNG&quot;,
&quot;industry&quot;
];
var records = DataGenerator.generateRecords(fields, { numRows: 50, seed: 0 });
var config = {
textSelect: true,
columns: [
{
field: fields[0],
name: &quot;ID&quot;
},
{
field: fields[1],
name: &quot;Company Name&quot;
},
{
field: fields[2],
name: &quot;Market&quot;
},
{
field: fields[3],
name: &quot;Last&quot;
},
{
field: fields[4],
name: &quot;Net. Chng&quot;
},
{
field: fields[5],
name: &quot;Industry&quot;
},
],
staticDataRows: records
};

var grid = document.getElementById(&quot;grid&quot;);
grid.config = config;
window.grid = grid;
</code></pre>
</code-sandbox><h2 id="copying-all-content-in-the-grid-without-text-selection">Copying all content in the grid without text selection</h2>
<p>If you want to copy all the data in the grid, you can do it by focusing on the grid element and modifying the clipboard without text selection.
To do this, you can listen for the <code>click</code> event on the grid element and call <code>focus</code> method on the grid API to focus on the grid.
Then, you can listen for the <code>copy</code> event on the grid element and modify the clipboard as shown in the example below.</p>
<h3 id="example-2">Example</h3>
<code-sandbox hash="9730f9b3"><pre><code class="language-css">html body {
padding: 5px;
box-sizing: border-box;
}
html hr {
margin: 5px;
}
efx-grid {
height: 200px;
}
efx-grid:focus-within {
outline-width: 1px;
outline-style: solid;
outline-color: blue;
}
textarea {
width: 100%;
height: 200px;
}
mark {
opacity: 0;
padding: 4px;
transition: opacity 0.5s ease-out;
}
</code></pre>
<pre><code class="language-html">&lt;big&gt;Try clicking grid and copying (&lt;b&gt;Ctrl/Command + C&lt;/b&gt;) grid&#39;s content.&lt;/big&gt;
&lt;br&gt;
&lt;big&gt;Then, paste the content on the text box below.&lt;/big&gt;
&lt;hr&gt;
&lt;mark id=&quot;key_indi&quot;&gt;&lt;/mark&gt;
&lt;hr&gt;
&lt;efx-grid id=&quot;grid&quot;&gt;&lt;/efx-grid&gt;
&lt;hr&gt;
&lt;textarea placeholder=&quot;Paste clipboard content here&quot;&gt;&lt;/textarea&gt;
</code></pre>
<pre><code class="language-javascript">import { halo } from &#39;./theme-loader.js&#39;; // This line is only required for demo purpose. It is not relevant for your application.
await halo(); // This line is only required for demo purpose. It is not relevant for your application.

/* ---------------------------------- Note ----------------------------------
DataGenerator, Formatters and extensions are exposed to global scope
in the bundle file to make it easier to create live examples.
Importing formatters and extensions is still required in your application.
Please see the document for further information.
---------------------------------------------------------------------------*/

var fields = [&quot;id&quot;, &quot;companyName&quot;, &quot;market&quot;, &quot;CF_LAST&quot;, &quot;CF_NETCHNG&quot;, &quot;industry&quot;];
var records = DataGenerator.generateRecords(fields, { seed: 0, numRows: 20 });

function onClick(e) {
grid.api.focus();
}
function onCopy(e) {
var columnNames = grid.api.getColumnNames();
var rows = grid.api.getMultipleRowData(); // Get all row data from existing view

// Build text in TSV format
var text = columnNames.join(&quot;\t&quot;) + &quot;\n&quot; +
rows.map(recordToTSV).join(&quot;\n&quot;);

e.clipboardData.setData(&quot;text/plain&quot;, text);
e.preventDefault();

showKeyIndicator(&quot;Data is copied to clipboard&quot;);
}
function recordToTSV(record) {
return ([
record[fields[0]],
record[fields[1]],
record[fields[2]],
record[fields[3]],
record[fields[4]]
]).join(&quot;\t&quot;); // TSV (Tab Separated Values)
}
function showKeyIndicator(text) {
if(text) {
key_indi.textContent = text;
}
key_indi.style.opacity = &quot;1&quot;;
setTimeout(onHideKeyIndicator, 1000);
}
function onHideKeyIndicator() {
key_indi.style.opacity = &quot;&quot;;
}

var configObj = {
sorting: {
sortableColumns: true
},
columns: [
{ name: &quot;Id&quot;, field: fields[0], width: 40 },
{ name: &quot;Company&quot;, field: fields[1] },
{ name: &quot;Market&quot;, field: fields[2], width: 100 },
{ name: &quot;Last&quot;, field: fields[3], width: 80 },
{ name: &quot;Net. Chng&quot;, field: fields[4], width: 80 },
{ name: &quot;Industry&quot;, field: fields[5] }
],
staticDataRows: records,
extensions: []
};

var grid = document.getElementById(&quot;grid&quot;);
grid.config = configObj;

grid.addEventListener(&quot;click&quot;, onClick);
grid.addEventListener(&quot;copy&quot;, onCopy);
</code></pre>
</code-sandbox><p><br><br></p>
67 changes: 22 additions & 45 deletions template-101.html
Original file line number Diff line number Diff line change
@@ -1,52 +1,29 @@
<h1 id="formatter-default">Formatter (default)</h1>
<p>Formatter is what Grid uses to render content. Grid&#39;s default formatter will render any data in plain text. When data is updated, Grid will bind the data from its own internal data source to render the data in plain text using the formatter. The data given to grid can be any data type.</p>
<h1 id="changing-formatter-at-runtime">Changing Formatter at Runtime</h1>
<p>Sometimes you might want to change a custom rendering at runtime. This can be achieved by using <code>setColumnFormatter</code> method.</p>
<blockquote>
<p>Note: The formatter will be repeatedly executed multiple times for every update and scrolling. </p>
<p>APIs for Grid and the <code>setColumnFormatter()</code> method description can be found <a href="#/apis/rt-grid/grid">here</a>.</p>
</blockquote>
<p>Default rendering is already optimized for row virtualization. This means that grid uses the same text element to render different data for different rows. It should be fast enough to handle rendering a million of rows.</p>
<p>To update what is shown on the Grid, please use Grid&#39;s APIs to <a href="#/general-concept/accessing-data">manipulate the data</a> from the instance.</p>
<h2 id="example">Example</h2>
<code-sandbox hash="910e0fa0"><pre><code class="language-css">efx-grid {
height: 200px;
}
</code></pre>
<pre><code class="language-html">&lt;efx-grid id=&quot;grid&quot;&gt;&lt;/efx-grid&gt;
</code></pre>
<pre><code class="language-javascript">import { halo } from &#39;./theme-loader.js&#39;; // This line is only required for demo purpose. It is not relevant for your application.
await halo(); // This line is only required for demo purpose. It is not relevant for your application.
<pre><code class="language-js">var grid = document.getElementsByTagName(&quot;efx-grid&quot;)[0];

/* ---------------------------------- Note ----------------------------------
DataGenerator, Formatters and extensions are exposed to global scope
in the bundle file to make it easier to create live examples.
Importing formatters and extensions is still required in your application.
Please see the document for further information.
---------------------------------------------------------------------------*/
var fields = [&quot;companyName&quot;, &quot;market&quot;, &quot;CF_LAST&quot;, &quot;CF_NETCHNG&quot;, &quot;industry&quot;];
var records = DataGenerator.generateRecords(fields, { numRows: 40 });
var configObj = {
columns: [
{name: &quot;Company&quot;, field: fields[0]},
{name: &quot;Market&quot;, field: fields[1]},
{name: &quot;Last&quot;, field: fields[2]},
{name: &quot;Net. Chng&quot;, field: fields[3]},
{name: &quot;Industry&quot;, field: fields[4]}
],
staticDataRows: records
// formatter can be a function
var formatter = function(e) {
var value = e.grid.getRowData(e.rowIndex)[e.field];
e.cell.setContent(value);
};

var grid = document.getElementById(&quot;grid&quot;);
grid.config = configObj;
</code></pre>
</code-sandbox><h2 id="internal-default-formatter-implementation">Internal Default Formatter Implementation</h2>
<p>Internally, Grid implements the formatter as the following code: </p>
<pre><code class="language-js">var configObj = {
columns: [
{ binding: function(e){
e.cell.setContent(e.data);
}
}
]
/*
// or can be an object.
var formatter = {
binding: function(e) {
var value = e.grid.getRowData(e.rowIndex)[e.field];
e.cell.setContent(value);
}
};
// or can be a predefined formatter
var formatter = SimpleLinkFormatter.create()
*/

function handleChangeFormatter() {
grid.api.setColumnFormatter(0 /* Column Index */, formatter);
}
</code></pre>
<h1 id="custom-formatter">Custom Formatter</h1>
<p>If we want anything other than simple text, we need to define a custom formatter. You can find more details about this in the <a href="#/rendering/custom-formatter">Custom Formatter section</a>.</p>
Loading

0 comments on commit 9072710

Please sign in to comment.