-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-145.html
68 lines (62 loc) · 3.33 KB
/
template-145.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<h1 id="get-sorting-statesreset-all">Get Sorting States/Reset All</h1>
<p>The <code>getSortedColumns()</code> method returns an array of the currently applied sorting states (with the <code>colIndex</code> and <code>sortOrder</code> properties).</p>
<p>Additionally, the <code>clearSortState()</code> method resets the current sorting states to their default neutral state.</p>
<p>A list of all sorting-related events can be found in the <strong>Events Handling</strong> section.</p>
<pre><code class="language-js">var sort = grid.api.getCoreGrid().getPlugin("SortableTitle");
var states = sort.getSortedColumns(); // Return an array of the current active sorting states
sort.clearSortState(); // Reset all sorting states to neutral
</code></pre>
<h2 id="example">Example</h2>
<code-sandbox hash="b25f8ce1"><pre><code class="language-css">efx-grid {
height: 200px;
}
textarea {
width: 100%;
height: 50px;
margin: 10px 0;
}
</code></pre>
<pre><code class="language-html"><button id="get_btn">Get Current States</button>
<button id="reset_btn">Clear All Sorting</button>
<textarea id="output_ta" placeholder="Click at the grid header to sort"></textarea>
<efx-grid id="grid"></efx-grid>
</code></pre>
<pre><code class="language-javascript">import { halo } from './theme-loader.js'; // 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 = ["companyName", "market", "CF_LAST", "CF_NETCHNG", "industry"];
var records = DataGenerator.generateRecords(fields, { numRows: 10 });
var configObj = {
sorting: {
sortableColumns: true,
threeStatesSorting: true
},
columns: [
{name: "Company", field: fields[0]},
{name: "Market", field: fields[1], width: 120},
{name: "Last", field: fields[2], width: 100},
{name: "Net. Chng", field: fields[3], width: 100},
{name: "Industry", field: fields[4]}
],
staticDataRows: records
};
var grid = document.getElementById("grid");
grid.config = configObj;
document.getElementById("get_btn").addEventListener("click", function() {
// Return an array of the current active sorting states
var sort = grid.api.getCoreGrid().getPlugin("SortableTitle");
var states = sort.getSortedColumns();
var ta = document.getElementById('output_ta');
ta.value = JSON.stringify(states, 2, null) + "\n" + ta.value;
});
document.getElementById("reset_btn").addEventListener("click", function() {
var sort = grid.api.getCoreGrid().getPlugin("SortableTitle");
sort.clearSortState();
});
</code></pre>
</code-sandbox>