Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

row().show().js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * This plugin permits to show the right page of DataTable to show the selected row
  3. *
  4. * @version 1.0
  5. * @name row().show()
  6. * @summary See the row in datable by display the right pagination page
  7. * @author [Edouard Labre](http://www.edouardlabre.com)
  8. *
  9. * @param {void} a row must be selected
  10. * @returns {DataTables.Api.Rows} DataTables Rows API instance
  11. *
  12. * @example
  13. * // Add an element to a huge table and go to the right pagination page
  14. * var table = $('#example').DataTable();
  15. * var new_row = {
  16. * DT_RowId: 'row_example',
  17. * name: 'example',
  18. * value: 'an example row'
  19. * };
  20. *
  21. * table.row.add( new_row ).draw().show().draw(false);
  22. */
  23. $.fn.dataTable.Api.register('row().show()', function() {
  24. var page_info = this.table().page.info();
  25. // Get row index
  26. var new_row_index = this.index();
  27. // Row position
  28. var row_position = this.table().rows()[0].indexOf( new_row_index );
  29. // Already on right page ?
  30. if( row_position >= page_info.start && row_position < page_info.end ) {
  31. // Return row object
  32. return this;
  33. }
  34. // Find page number
  35. var page_to_display = Math.floor( row_position / this.table().page.len() );
  36. // Go to that page
  37. this.table().page( page_to_display );
  38. // Return row object
  39. return this;
  40. });