I don't have an example of that, but one way of doing it is simply to call the click function on the rows you want selected after the table has been drawn ( $('tbody tr:eq(0)').click() for example would select the first row).
It maybe a problem with strings and arrays. Perhaps the database is returning string data and the isarray() requires integers. Try adding parseInt() to thecode you have.
e.g.
[code]
if ( jQuery.inArray( parseInt( aData[0] ), gaiSelected ) != -1 ){
$(nRow).addClass('row_selected');
}
[/code]
Replies
Allan
[code]
function InitTable() {
/* Init the table */
oTable = $("#tblData").dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "Data.ashx",
"sPaginationType": "full_numbers",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
"aaSorting": [[1, "desc"]],
"aoColumns": [null, null, null, { "bSortable": false, "sWidth": "15px"}],
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
$('#tblData tbody tr').each(function () {
if (jQuery.inArray(aData[0], selected) != -1) {
$(this).addClass('row_selected');
}
});
return nRow;
},
"fnDrawCallback": function (oSettings) {
$('#tblData tbody tr').each(function () {
var iPos = oTable.fnGetPosition(this);
if (iPos != null) {
var aData = oTable.fnGetData(iPos);
if (jQuery.inArray(aData[0], selected) != -1)
$(this).addClass('row_selected');
}
$(this).click(function () {
var iPos = oTable.fnGetPosition(this);
var aData = oTable.fnGetData(iPos);
var iId = aData[0];
is_in_array = jQuery.inArray(iId, selected);
if (is_in_array == -1) {
selected[selected.length] = iId;
}
else {
selected = jQuery.grep(selected, function (value) {
return value != iId;
});
}
if ($(this).hasClass('row_selected')) {
$(this).removeClass('row_selected');
}
else {
$(this).addClass('row_selected');
}
});
});
}
});
}
[/code]
e.g.
[code]
if ( jQuery.inArray( parseInt( aData[0] ), gaiSelected ) != -1 ){
$(nRow).addClass('row_selected');
}
[/code]