dataTables.pluginAPI.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) {
  2. //redraw to account for filtering and sorting
  3. // concept here is that (for client side) there is a row got inserted at the end (for an add)
  4. // or when a record was modified it could be in the middle of the table
  5. // that is probably not supposed to be there - due to filtering / sorting
  6. // so we need to re process filtering and sorting
  7. // BUT - if it is server side - then this should be handled by the server - so skip this step
  8. if(oSettings.oFeatures.bServerSide === false){
  9. var before = oSettings._iDisplayStart;
  10. oSettings.oApi._fnReDraw(oSettings);
  11. //iDisplayStart has been reset to zero - so lets change it back
  12. oSettings._iDisplayStart = before;
  13. oSettings.oApi._fnCalculateEnd(oSettings);
  14. }
  15. //draw the 'current' page
  16. oSettings.oApi._fnDraw(oSettings);
  17. };
  18. $.fn.dataTableExt.oApi.fnAddDataAndDisplay = function ( oSettings, aData )
  19. {
  20. /* Add the data */
  21. var iAdded = this.oApi._fnAddData( oSettings, aData );
  22. var nAdded = oSettings.aoData[ iAdded ].nTr;
  23. /* Need to re-filter and re-sort the table to get positioning correct, not perfect
  24. * as this will actually redraw the table on screen, but the update should be so fast (and
  25. * possibly not alter what is already on display) that the user will not notice
  26. */
  27. this.oApi._fnReDraw( oSettings );
  28. /* Find it's position in the table */
  29. var iPos = -1;
  30. for( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
  31. {
  32. if( oSettings.aoData[ oSettings.aiDisplay[i] ].nTr == nAdded )
  33. {
  34. iPos = i;
  35. break;
  36. }
  37. }
  38. /* Get starting point, taking account of paging */
  39. if( iPos >= 0 )
  40. {
  41. oSettings._iDisplayStart = ( Math.floor(i / oSettings._iDisplayLength) ) * oSettings._iDisplayLength;
  42. this.oApi._fnCalculateEnd( oSettings );
  43. }
  44. this.oApi._fnDraw( oSettings );
  45. return {
  46. "nTr": nAdded,
  47. "iPos": iAdded
  48. };
  49. }