1- import { Component , h , State } from '@stencil/core' ;
1+ import { Component , h , Host , State } from '@stencil/core' ;
22import { Column } from '@limetech/lime-elements' ;
33import { invoices , Invoice } from './invoices' ;
44
@@ -9,8 +9,13 @@ import { invoices, Invoice } from './invoices';
99 * a column header. An arrow icon on the header visualizes the
1010 * direction of sorting, when a column is sorted.
1111 *
12- * However, you can disable the sorting possibility in individual columns,
13- * by setting the `headerSort` to `false`.
12+ * To prevent sorting altogether, set the `sortableColumns` property on
13+ * `limel-table` to `false`. If you only want to disable sorting for a
14+ * specific column, set the column's `headerSort` property to `false`.
15+ *
16+ * The "Reference Person" column below has sorting disabled on the
17+ * column definition, while the control lets you disable sorting for
18+ * the whole table.
1419 *
1520 * @sourceFile invoices.ts
1621 */
@@ -24,18 +29,43 @@ export class TableExampleSortingDisabled {
2429 private tableData : Invoice [ ] = invoices ;
2530
2631 @State ( )
27- public columns : Column [ ] = [
32+ private disableAllSorting : boolean = false ;
33+
34+ @State ( )
35+ private columns : Column [ ] = [
2836 { title : 'Invoice no.' , field : 'invoiceNumber' } ,
2937 { title : 'Invoice Date' , field : 'invoiceDate' } ,
3038 {
31- title : 'Reference Person' ,
39+ title : 'Reference Person (no sorting) ' ,
3240 field : 'referencePerson' ,
3341 headerSort : false ,
3442 } ,
3543 { title : 'Amount' , field : 'amount' , horizontalAlign : 'right' } ,
3644 ] ;
3745
3846 render ( ) {
39- return < limel-table data = { this . tableData } columns = { this . columns } /> ;
47+ return (
48+ < Host >
49+ < limel-table
50+ data = { this . tableData }
51+ columns = { this . columns }
52+ sortableColumns = { ! this . disableAllSorting }
53+ />
54+ < limel-example-controls
55+ style = { { '--example-controls-column-layout' : 'auto-fit' } }
56+ >
57+ < limel-checkbox
58+ checked = { this . disableAllSorting }
59+ label = "Disable sorting on all columns"
60+ onChange = { this . setDisableAllSorting }
61+ />
62+ </ limel-example-controls >
63+ </ Host >
64+ ) ;
4065 }
66+
67+ private setDisableAllSorting = ( event : CustomEvent < boolean > ) => {
68+ event . stopPropagation ( ) ;
69+ this . disableAllSorting = event . detail ;
70+ } ;
4171}
0 commit comments