DataTables: Custom priority sorting

DataTables: Custom priority sorting

by Shrikrishna Gupta

HTML

<link rel="stylesheet" href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.5.6/css/buttons.dataTables.min.css">
<script src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js"></script>
<table id="example" class="display" style="width:100%">
	<thead>
		<tr>
			<th>Name</th>
			<th>Position</th>
			<th>Priority</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>Tiger Nixon1</td>
			<td>System Architect</td>
			<td>High</td>
		</tr>
		<tr>
			<td>Garrett Winters</td>
			<td>Accountant</td>
			<td>Medium</td>
		</tr>
		<tr>
			<td>Ashton Cox</td>
			<td>Junior Technical Author</td>
			<td>Low</td>
		</tr>
		<tr>
			<td>Cedric Kelly</td>
			<td>Senior Javascript Developer</td>
			<td>Unprioritized</td>
		</tr>
		<tr>
			<td>Airi Satou</td>
			<td>Accountant</td>
			<td>N/A</td>
		</tr>
		<tr>
			<td>Brielle Williamson</td>
			<td>Integration Specialist</td>
			<td>High</td>
		</tr>
		<tr>
			<td>Herrod Chandler</td>
			<td>Sales Assistant</td>
			<td>N/A</td>
		</tr>
	</tbody>
</table>

JavaScript

$('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            {
                text: 'My button',
                action: function ( e, dt, node, config ) {
                var data = dt.rows( { selected: true } ).data().toArray();
                var json = JSON.stringify(data)
                localStorage.setItem('exportedData', json);
                }
            },
            {
                text: 'My button1',
                action: function ( e, dt, node, config ) {
                var data = JSON.parse(localStorage.getItem('exportedData'));
                dt.clear();
                dt.rows.add(data).draw();
                }
            }
        ]
    } );