accessing custom param from cookie

accessing custom param from cookie

ramyaramya Posts: 5Questions: 0Answers: 0
edited September 2011 in General
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

Replies

  • ramyaramya Posts: 5Questions: 0Answers: 0
    After trying hard to solve this row selection problem after auto refresh, I ended up using javascript cookie.
    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]
  • GregPGregP Posts: 500Questions: 10Answers: 0
    This approach makes sense to me, too. I am doing drill-down-detail rows, but I also do polling. We have a "pause" button on the UI, and the end user is basically expected to pause if they want to view details for any length of time.

    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!
  • ramyaramya Posts: 5Questions: 0Answers: 0
    Thank you so much for your comment!
This discussion has been closed.