DEV kevin's tweak for row().show()

pull/461/head
Colin Marks 5 years ago
parent 40abbc1dc4
commit 6090a52b5b

@ -17,24 +17,26 @@
* name: 'example', * name: 'example',
* value: 'an example row' * value: 'an example row'
* }; * };
* *
* table.row.add( new_row ).draw().show().draw(false); * table.row.add( new_row ).draw().show().draw(false);
*/ */
$.fn.dataTable.Api.register('row().show()', function() { $.fn.dataTable.Api.register('row().show()', function() {
var page_info = this.table().page.info(); var page_info = this.table().page.info();
// Get row index // Get row index
var new_row_index = this.index(); var new_row_index = this.index();
// Row position // Row position
var row_position = this.table().rows()[0].indexOf( new_row_index ); var row_position = this.table()
// Already on right page ? .rows({ search: 'applied' })[0]
if( row_position >= page_info.start && row_position < page_info.end ) { .indexOf(new_row_index);
// Return row object // Already on right page ?
return this; if ((row_position >= page_info.start && row_position < page_info.end) || row_position < 0) {
} // Return row object
// Find page number return this;
var page_to_display = Math.floor( row_position / this.table().page.len() ); }
// Go to that page // Find page number
this.table().page( page_to_display ); var page_to_display = Math.floor(row_position / this.table().page.len());
// Return row object // Go to that page
return this; this.table().page(page_to_display);
// Return row object
return this;
}); });

Loading…
Cancel
Save