var table = new Y.DataTable({ columns: [ 'id', 'username', 'name', 'birthdate' ], data: [ ... ], sortable: true }); table.render('#table');
var table = new Y.DataTable({ columns: [ 'id', { key: 'username', sortable: true }, { key: 'name', sortable: true }, { key: 'birthdate', sortable: true } ], data: [ ... ] // sortable: 'auto' is the default }); // OR var table = new Y.DataTable({ columns: [ 'id', 'username', 'name', 'birthdate' ], data: [ ... ], sortable: [ 'username', 'name', 'birthdate' ] });
function nameSort(a, b, desc) { var aa = a.get('lastName') + a.get('firstName'), bb = a.get('lastName') + b.get('firstName'), order = (aa > bb) ? 1 : -(aa < bb); return desc ? -order : order; } var table = new Y.DataTable({ columns: [ 'id', 'username', { key: name, sortFn: nameSort }, 'birthdate' ], data: [ ... ], sortable: [ 'username', 'name', 'birthdate' ] });
var table = new Y.DataTable({ columns: [ ... ], data: [ ... ], sortBy: 'username' }); table.get('sortBy'); // 'username' table.get('sortBy.state'); // { key: 'username', dir: 1 } table.sort(['lastName', { firstName: "desc" }]); table.get('sortBy'); // ['lastName', { firstName: "desc" }] table.get('sortBy.state'); // [{ key: "lastName", dir: 1 }, { key: "firstName", dir: -1 }]