Sorting your table


1

Simple example

You can sort your javascript table by double a double click in the header, using the context menu or by javascript as follow:




Source code

<html>
<script src="https://bossanova.uk/jexcel/v3/jexcel.js"></script>
<script src="https://bossanova.uk/jsuites/v2/jsuites.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jexcel/v3/jexcel.css" type="text/css" />
<link rel="stylesheet" href="https://bossanova.uk/jsuites/v2/jsuites.css" type="text/css" />

<div id="spreadsheet"></div>

<script>
var data = [
    ['Mazda', 2001, 2000, '2006-01-01'],
    ['Pegeout', 2010, 5000, '2005-01-01'],
    ['Honda Fit', 2009, 3000, '2004-01-01'],
    ['Honda CRV', 2010, 6000, '2003-01-01'],
];

var table = jexcel(document.getElementById('spreadsheet'), {
    data:data,
    columns: [
        { type: 'text', width:300 },
        { type: 'text', width:80 },
        { type: 'text', width:100 },
        { type: 'calendar', width:100 },
    ]
});
</script>

<select id='columnNumber'>
<option value='0'>Column 1</option>
<option value='1'>Column 2</option>
<option value='2'>Column 3</option>
<option value='3'>Column 4</option>
</select>
<input type='button' value='Sort column' onclick="table.orderBy(document.getElementById('columnNumber').value)">

</html>

2

Disable the table sorting

The ordering is a native enabled feature. To disable that feature please use the columnSorting:false, directive in the initialization.

<script>
var data = [
    ['Mazda', 2001, 2000, '2006-01-01'],
    ['Pegeout', 2010, 5000, '2005-01-01'],
    ['Honda Fit', 2009, 3000, '2004-01-01'],
    ['Honda CRV', 2010, 6000, '2003-01-01'],
];

jexcel(document.getElementById('spreadsheet'), {
    data:data,
    columns: [
        { type: 'text', tile:'Model', width:300 },
        { type: 'text', tile:'Year', width:100 },
        { type: 'text', tile:'Price', width:100 },
        { type: 'text', tile:'Date', width:100 },
    ],
    columnSorting:false,
});
</script>