bSaveState & saving the state in a database...
bSaveState & saving the state in a database...
robertbrower
Posts: 158Questions: 1Answers: 0
I'd prefer to save the state of the datatable in what I call a shortcut in the underlying database of my application.
I am using server side processing.
I can get the display length, display start, and sorting info and save it in the database. Now I want to restore the state from what is saved in the database.
Is there a way to at least set the display length, display start, and sorting info without reinitializing the datatable?
Thanks,
Robert
I am using server side processing.
I can get the display length, display start, and sorting info and save it in the database. Now I want to restore the state from what is saved in the database.
Is there a way to at least set the display length, display start, and sorting info without reinitializing the datatable?
Thanks,
Robert
This discussion has been closed.
Replies
Allan
I'm going to try to write fnSorting. And since I only want to redraw one time after setting length, display start, and sorting, then I will have to combine all three plugins into one.
Does this sound correct? Thanks.
Robert
if (typeof bRedraw == 'undefined') {
bRedraw = true;
}
oSettings._iDisplayLength = iDisplayLength;
oSettings._iDisplayStart = iDisplayStart;
oSettings.aaSorting = aaSorting;
oSettings.oApi._fnCalculateEnd(oSettings);
/* If we have space to show extra rows (backing up from the end point - then do so */
if (oSettings._iDisplayEnd == oSettings.aiDisplay.length) {
oSettings._iDisplayStart = oSettings._iDisplayEnd - oSettings._iDisplayLength;
if (oSettings._iDisplayStart < 0) {
oSettings._iDisplayStart = 0;
}
}
if (oSettings._iDisplayLength == -1) {
oSettings._iDisplayStart = 0;
}
if (bRedraw) {
oSettings.oApi._fnDraw(oSettings);
}
if (oSettings.aanFeatures.l) {
$('select', oSettings.aanFeatures.l).val(iDisplayLength);
}
};
/* If we have space to show extra rows (backing up from the end point - then do so */
And it gives me what I need.
$.fn.dataTableExt.oApi.fnRestoreState = function (oSettings, iDisplayLength, iDisplayStart, aaSorting, bRedraw) {
if (typeof bRedraw == 'undefined') {
bRedraw = true;
}
//oSettings.oApi._fnCalculateEnd(oSettings);
oSettings._iDisplayLength = iDisplayLength;
oSettings._iDisplayStart = iDisplayStart;
oSettings._DisplayEnd = 0;
oSettings.aaSorting = aaSorting;
oSettings.oApi._fnCalculateEnd(oSettings);
if (oSettings._iDisplayLength == -1) {
oSettings._iDisplayStart = 0;
}
if (bRedraw) {
oSettings.oApi._fnDraw(oSettings);
}
if (oSettings.aanFeatures.l) {
$('select', oSettings.aanFeatures.l).val(iDisplayLength);
}
};
Allan
Allan
$.fn.dataTableExt.oApi.fnRestoreState = function (oSettings, iDisplayLength, iDisplayStart, aaSorting, sSearch, bRedraw) {
if (typeof bRedraw == 'undefined') {
bRedraw = true;
}
//oSettings.oApi._fnCalculateEnd(oSettings);
oSettings._iDisplayLength = iDisplayLength;
oSettings._iDisplayStart = iDisplayStart;
oSettings._DisplayEnd = 0;
oSettings.aaSorting = aaSorting;
oSettings.oPreviousSearch.sSearch = sSearch;
$(oSettings.nTable).closest(".dataTables_wrapper").find(".dataTables_filter").find("input").val(sSearch);
oSettings.oApi._fnCalculateEnd(oSettings);
if (oSettings._iDisplayLength == -1) {
oSettings._iDisplayStart = 0;
}
if (bRedraw) {
oSettings.oApi._fnDraw(oSettings);
}
if (oSettings.aanFeatures.l) {
$('select', oSettings.aanFeatures.l).val(iDisplayLength);
}
};