Skip to content

Instantly share code, notes, and snippets.

@reimertz
Last active November 10, 2018 22:05
Show Gist options
  • Save reimertz/700a1a3c61e17cb79a3e568e01567017 to your computer and use it in GitHub Desktop.
Save reimertz/700a1a3c61e17cb79a3e568e01567017 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SlickGrid example: Multi Column Sort</title>
<link rel="stylesheet" href="https://rawgit.com/mleibman/SlickGrid/master/slick.grid.css" type="text/css"/>
<link rel="stylesheet" href="https://rawgit.com/mleibman/SlickGrid/master/css/smoothness/jquery-ui-1.8.16.custom.css" type="text/css"/>
<link rel="stylesheet" href="https://rawgit.com/mleibman/SlickGrid/master/examples/examples.css" type="text/css"/>
</head>
<body>
<table width="100%">
<tr>
<td valign="top" width="100%">
<div id="myGrid" style="width:1000px;height:750px;"></div>
</td>
</tr>
</table>
<script src="https://rawgit.com/mleibman/SlickGrid/master/lib/jquery-1.7.min.js"></script>
<script src="https://rawgit.com/mleibman/SlickGrid/master/lib/jquery.event.drag-2.2.js"></script>
<script src="https://rawgit.com/mleibman/SlickGrid/master/slick.core.js"></script>
<script src="https://rawgit.com/mleibman/SlickGrid/master/slick.grid.js"></script>
<script>
var grid;
var columns = [
{
id: 'title',
name: 'title',
field: 'title',
sortable: true
},
{
id: 'description',
name: 'description',
field: 'description',
sortable: true
},
{
id: 'customUrl',
name: 'customUrl',
field: 'customUrl',
sortable: true
},
{
id: 'publishedAt',
name: 'publishedAt',
field: 'publishedAt',
sortable: true
},
{
id: 'thumbnails',
name: 'thumbnails',
field: 'thumbnails',
sortable: true
},
{
id: 'localized',
name: 'localized',
field: 'localized',
sortable: true
},
{
id: 'viewCount',
name: 'viewCount',
field: 'viewCount',
sortable: true
},
{
id: 'commentCount',
name: 'commentCount',
field: 'commentCount',
sortable: true
},
{
id: 'subscriberCount',
name: 'subscriberCount',
field: 'subscriberCount',
sortable: true
},
{
id: 'hiddenSubscriberCount',
name: 'hiddenSubscriberCount',
field: 'hiddenSubscriberCount',
sortable: true
},
{
id: 'videoCount',
name: 'videoCount',
field: 'videoCount',
sortable: true
}
];
var options = {
enableCellNavigation: true,
enableColumnReorder: false,
multiColumnSort: true
};
$(function ()
var data = JSON.parse({{hook.out}});
grid = new Slick.Grid("#myGrid", data, columns, options);
grid.onSort.subscribe(function (e, args) {
var cols = args.sortCols;
data.sort(function (dataRow1, dataRow2) {
for (var i = 0, l = cols.length; i < l; i++) {
var field = cols[i].sortCol.field;
var sign = cols[i].sortAsc ? 1 : -1;
var value1 = dataRow1[field], value2 = dataRow2[field];
var result = (value1 == value2 ? 0 : (value1 > value2 ? 1 : -1)) * sign;
if (result != 0) {
return result;
}
}
return 0;
});
grid.invalidate();
grid.render();
});
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment