accessing custom param from cookie
accessing custom param from cookie
Hi,
The table has the row select capability. As the table data needs to be refreshed periodically row selection disappears on page refresh.
So i am trying to save the selected row in cookie using "bstatesave" as custom param. Please tell me to read the cookie value back and use it.
"In the client side xsl stylesheet is been used to return html and server side returns dynamic content as xml."
This is how i have done in the js file:
[code]
function initTable(rowSelected) {
return $('#example').dataTable( {
"bSortClasses" : false,
"bStateSave" : true,
"bPaginate" : false,
"bLengthChange" : false,
"bFilter" : false,
"bInfo" : false,
"bAutoWidth" : false,
"bRetrieve" : true,
"sScrollX": "",
"sScrollY": "200px",
"fnStateSaveCallback": function ( oSettings, sValue ) {
sValue += ',"myCustomParam": "'+rowSelected+'"';
return sValue;
}
});
}
$(document).ready(function() {
oTable = initTable();
/* select single row */
$('#example tbody tr').live('click', function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
});
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i
The table has the row select capability. As the table data needs to be refreshed periodically row selection disappears on page refresh.
So i am trying to save the selected row in cookie using "bstatesave" as custom param. Please tell me to read the cookie value back and use it.
"In the client side xsl stylesheet is been used to return html and server side returns dynamic content as xml."
This is how i have done in the js file:
[code]
function initTable(rowSelected) {
return $('#example').dataTable( {
"bSortClasses" : false,
"bStateSave" : true,
"bPaginate" : false,
"bLengthChange" : false,
"bFilter" : false,
"bInfo" : false,
"bAutoWidth" : false,
"bRetrieve" : true,
"sScrollX": "",
"sScrollY": "200px",
"fnStateSaveCallback": function ( oSettings, sValue ) {
sValue += ',"myCustomParam": "'+rowSelected+'"';
return sValue;
}
});
}
$(document).ready(function() {
oTable = initTable();
/* select single row */
$('#example tbody tr').live('click', function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
});
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i
This discussion has been closed.
Replies
As i had a row with unique id in the table, saved this id in cookie after each row selection.
[code]
$("#Table tbody tr").live('click', function(event) {
var aData = oTable.fnGetData(this);
// save the unique id in cookie
setCookie("myTableRow","unique_" +aData[0],1);
...
...
}
[/code]
I also associated each element with this id at the time of creating table elements in XSLT. (example: )
And added the CSS class for row selection after each auto refresh,
[code]
"fnDrawCallback": function() {
var selectedRow = getCookie("myTableRow");
$("table#myTable tr").each(function (i) {
if($(this).attr('id')==selectedRow)
{
$(this).addClass('row_selected');
}
});
}
[/code]
Based on this cookie approach, I could see how instead of just addClass() I could create a whole function to find and re-pop the drilldown row if it's still available on the current page. Hrm... thanks for posting your solution!