Is it possible to display records based on custom criteria first before display others?
Is it possible to display records based on custom criteria first before display others?
I have checked the docs and examples on DataTables being able to sort or order rows according to a data type or using custom values, but however the objective that I am trying to achieve is different.
What I am trying to accomplish is to display a set of rows according to a custom criteria first, before displaying other rows.
Let me show an example:
ID - AssignedPerson - RequestNum - Date
1 - Beck - ABC012 - 01/02/2013
2 - Erin - BCD321 - 03/06/2014
3 - Fiona - CDE234 - 04/07/2014
4 - Erin - DEF345 - 05/07/2014
Notice that if I were to perform sorting or ordering of columns, I can only go either by ascending/descending order, numeric or alphabetical only. In this example, if I sort by AssignedPerson, I only get Beck -Erin - Erin - Fiona.
But what happens if I wish to display results to be more like this instead:
2 - Erin - BCD321 - 03/06/2014
4 - Erin - DEF345 - 05/07/2014
1 - Beck - ABC012 - 01/02/2013
3 - Fiona - CDE234 - 04/07/2014
Notice that for column AssignedPerson, Erin having started with an E falls between B (Beck) and F (Fiona).
I believed that it has to do with the way the rows are presented inside the Editor JS file when the results are retrieved from Editor.php file. But how do I accomplish this?
I remembered seeing an example in the Editor docs that does something somewhat similar, but I think it's different ultimately.
Pay attention to the section on "drawCallback" here:
var table = $('#MyTable').DataTable( {
dom: "Tfrtip",
ajax: "php/MyEditor.php",
columns: [
{ data: "PutWhatEverColumnsDataHere"}
],
tableTools: {
sRowSelect: "os",
aButtons: [
{ sExtends: "editor_create",
editor: adder,
sButtonText: "New Entry"
},
{ sExtends: "editor_edit",
editor: editor,
sButtonText: "Update Existing Entry"
}
]
},
"drawCallback": function ( settings ) {
var api = this.api();
var rows = api.rows( {page:'current'} ).nodes();
var last = null;
api.column(1, {page:'current'} ).data().each( function ( AssignedPerson, i ) {
if ( last !== AssignedPerson ) {
$(rows).eq( i ).before(
'<tr class="AssignedPerson"><td colspan="18">'+AssignedPerson+'</td></tr>'
);
last = AssignedPerson;
}
} );
},