javascript - Datatables.net fnGetPosition returns -1 for iColumnIndex when adding a new row and then clicking on the row 0 -


i getting position using:

this.fngetposition = function( nnode )     {         var osettings = _fnsettingsfromnode( this[datatable.ext.iapiindex] );         var snodename = nnode.nodename.touppercase();          if ( snodename == "tr" )         {             return _fnnodetodataindex(osettings, nnode);         }         else if ( snodename == "td" || snodename == "th" )         {             var idataindex = _fnnodetodataindex( osettings, nnode.parentnode );             var icolumnindex = _fnnodetocolumnindex( osettings, idataindex, nnode );             return [ idataindex, _fncolumnindextovisible(osettings, icolumnindex ), icolumnindex ];         }         return null;     }; 

if click row 0, idataindex contains 0 , icolumnindex contains whatever column clicked in. if add new row, lets row 9 , click row 0, idataindex still holds 9 instead of 0 , icolumnindex returns -1. have turn bserverside off when adding new row because if don't, clicking add new row button not add blank row, make ajax call. once add row, turn bserverside on.

fnnodetodataindex looks this:

function _fnnodetodataindex( osettings, n )     {         return (n._dt_rowindex!==undefined) ? n._dt_rowindex : null;     } 

fnnodetocolumnindex looks this:

function _fnnodetocolumnindex( osettings, irow, n )     {         var ancells = _fngettdnodes( osettings, irow );          ( var i=0, ilen=osettings.aocolumns.length ; i<ilen ; i++ )         {             if ( ancells[i] === n )             {                 return i;             }         }         return -1;     } 

this function gets called when want add new row:

/* add single row , display */ $.fn.datatableext.oapi.fnadddataanddisplay = function(osettings, adata) { /* add data */ var iadded = this.oapi._fnadddata(osettings, adata); var nadded = osettings.aodata[iadded].ntr;  /* need re-filter , re-sort table positioning correct, not perfect * redraw table on screen, update should fast (and * possibly not alter on display) user not notice */ this.oapi._fnredraw(osettings);  /* find it's position in table */ var ipos = iadded;  /* starting point, taking account of paging */ if (ipos >= 0) {     osettings._idisplaystart = (math.floor(ipos / osettings._idisplaylength)) * osettings._idisplaylength;     this.oapi._fncalculateend(osettings); }  this.oapi._fndraw(osettings); return {     "ntr": nadded,     "ipos": iadded }; 

};


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -