jquery DataTables plugin: can you capture server-side data other than the JSON expected by the plugin? -


i'm using "bserverside": true, "sajaxsource":, , "fnserverdata":... populate datatable. working fine.

 "bfilter": true, "bsort": true,  "bsortclasses": true,  "bprocessing": true, "bserverside": true, "sajaxsource": "my_page_that_outputs_json.asp",  "fnserverdata": function ( ssource, aodata, fncallback ) {     aodata.push( { "name": "my_custom_var"  , "value": $('#somecustomvar').val() } );                        $.getjson( ssource, aodata, function (json) {          fncallback(json);       } ); }, 

however, when make call server, want return more json page connecting server. have additional recordsets i'd return 1 call database, possible within datatables framework? page outputting json, when retrieved datatable, expecting json, , gives error when other elements present.

update 1: don't know if proper route take, i'm thinking 1 options use datatables hidden column feature. http://www.datatables.net/examples/basic_init/hidden_columns.html suppose stuff elements id's in single cell in hidden column, , access id's info via jquery.

update 2: maybe how other elements on parent page can updated elements in json response page (i've posed issue in datatables forum, no response):

  1. add , include id's each hidden input in first row of json data

  2. don't try hidden columns, because elements seem inaccessible when column hidden. (if i'm wrong this, please inform...)

  3. if hidden input needs rendered once, so

  4. access hidden input via jquery on parent page

update 3: @jm4 - don't know address question, able use hidden input route - e.g.,<input type="hidden id="mycustomid_012" /> - , done needed do.

i used function similar following handle row click. function outside of datatable build.

function clickrowhandler() { /* highlight selected row on single click */ $('.tblintrepid tbody tr').click(function(event) {     $(otable.fnsettings().aodata).each(function (){         $(this.ntr).removeclass('row_selected');     });      // update myintrepidid value form "complete" submission             // myintrepidid on page, not in datatable     var mynewintrepidid = $(this).find("td:first input").val();      $('#myintrepidid').val(mynewintrepidid);      // set row class     $(event.target.parentnode).toggleclass('row_selected');     });    /* more details */   } 

inside datatable build, clickrowhandler function called in manner:

"fndrawcallback": function() {         clickrowhandler(); }, 

also, can't remember saw in datatables forum (probably started here: http://datatables.net/forums/comments.php?discussionid=3931) route can use output json data above-and-beyond datatables requires. so, while need output json includes "secho" , "itotalrecords" , "itotaldisplayrecords" , "aadata", can make own name/value pairs.

if had list of 10 usernames wanted in select dropdown in table header, build name/value pair in place build json, , call "selectusernames". in datatables build, turn custom json object list (i'm not displaying of functions here):

this function, outside of datatables build, creates select dropdown. // http://datatables.net/forums/comments.php?discussionid=3931&page=1#item_6

function fncreateselect( adata ) {     var r='<select><option value=""></option>', i, ilen=adata.length;     //alert(ilen);      ( i=0 ; i<ilen ; i++ )     {         r += '<option value="'+adata[i]+'">'+adata[i]+'</option>';     }     return r+'</select>'; } 

and inside datatables build...

  $.getjson( ssource, aodata, function (json) {       if ( json.secho == 1 ) {         $("thead td.search").each( function () {  /* insert select menu */ this.innerhtml = fncreateselect(json.selectusernames);  /* add event listener newly created element */    $('select', this).change( function () {      otable.fnfilter( $(this).val(), 8 );    }); }); 

if use drawcallback add class current row (for exemple add selected class), possible retrieve hidden values.

here fndrawcallback function add 'row_selected' class on current row. works if row class.

"fndrawcallback": function(){   $('td').bind('mouseenter', function () { $(this).parent().addclass('row_selected').css('cursor', 'pointer'); });   $('td').bind('mouseleave', function () { $(this).parent().removeclass('row_selected'); }); }, 

the problem when populate table json nodename of selected node undefined. instead of this, can find row selected class

$("#leadlist tbody").click(function(event) {   var atrs = table.fngetnodes();   ( var i=0 ; i<atrs.length ; i++ ) {     if ($(atrs[i]).hasclass('row_selected') ) {       // here data without need of fngetposition       var adata = table.fngetdata( );       location.href='mylink/' + adata[0];     }   } }); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -