Click here to Skip to main content
15,888,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

Im trying to change the row order of the table when a button clicked based on rows selected.
like i want to display the selected rows first then the remaining rows in Jquery Datatable.



you can see rowseleted each which is meant to display the rows selected first im unable to get the data which is not selected. can any one help me out

What I have tried:

here is the script i tried so far.

Quote:
$('#reloadID').click(function () { var prevSelection = "";
var tr = $(this).closest('tr');
var rowsSelected = table.rows('.selected').data();
var complete = table.rows().data();
//var nonselected = table.row(tr).node().className;
//var test = $("#mytbl").dataTable().fnGetNodes().className;

// console.log(nonselected);
var mcb = '<th/>';
var vendorsTable = '<table id="mytbl">
<thead>
<tr>' + mcb + '<th>xyz</th>
<th>zy</th>
<th>xyz</th>
<th>xy</th>';
vendorsTable = vendorsTable + '<th>City</th>
<th>State</th>
<th>Zip</th>
</tr>
</thead>
<tbody>';



$.each(rowsSelected, function () {
var $this1 = this;

if ($this1[2] + "," + "," != prevSelection) {
var selected = "";
var ccb = '<td/>';
vendorsTable = vendorsTable + '<tr class="">' + ccb + '<td>' + $this1[1] + '</td>
<td>' + $this1[2] + '</td>
<td>' + $this1[3] + '</td>
<td>' + $this1[4] + '</td>'
+ '<td>' + $this1[5] + '</td>
<td>' + $this1[6] + '</td>
<td>' + $this1[7] + '</td>'
+ '</tr>';
prevSelection = $this1[2] + "," + ",";
}



});

vendorsTable = vendorsTable + '</tbody>
</table>';
$('#Vendors').empty();

$('#Vendors').append(vendorsTable);
//Initialize the table generated with datatable plug-in
table = $('#mytbl').DataTable({
"oLanguage": { "sSearch": "" },
columnDefs: [{
orderable: true,
className: 'select-checkbox',
targets: 0
}],
select: {
style: 'multi',
selector: 'td:first-child'
},

dom: 'T<"clear">lfrtip',
tableTools: {
"sRowSelect": "multi",
"aButtons": ["select_all", "select_none",
{
"sExtends": "select_all",
"sButtonText": "Select Filtered",
"fnClick": function (nButton, oConfig, oFlash) {
var oTT = TableTools.fnGetInstance('mytbl');
//remove previous selections
oTT.fnSelectNone();
oTT.fnSelectAll(true); //True = Select only filtered rows (true). Optional - default false.
}
},
{
"sExtends": "select_none",
"sButtonText": "Deselect Filtered",
"fnClick": function (nButton, oConfig, oFlash) {
var oTT = TableTools.fnGetInstance('mytbl');
//remove previous selections
oTT.fnSelectNone(true);
}
}

]
},
order: [1, 'asc']

}
});


} });
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900