range selecting rows regardless of sorting/filtering

range selecting rows regardless of sorting/filtering

abargnesiabargnesi Posts: 2Questions: 0Answers: 0
edited September 2009 in General

It's my first post so I'll take this chance to say, great plugin! This component has a bunch of features standard that are really useful. I also needed JQuery UI added in there so I borrowed the code provided by "bchic869" (post - http://datatables.net/forums/comments.php?DiscussionID=528&page=1#Item_0).

The one thing I find missing though is a standard api for row selection using Control and Shift keys. I ran into an issue where I wanted to select multiple rows regardless of sorting or filtering. I found that the function [code]fnGetPosition(row);[/code] gets the order of the TR element within the TBODY instead of where it is currently displayed.

I ended up adding the following function to select a range based on the actual "Display Order" of the row:

this.fnRangeSelect = function(nodeOne, nodeTwo) {
var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
var domPositionOne = this.fnGetPosition(nodeOne);
var domPositionTwo = this.fnGetPosition(nodeTwo);

var displayPositionOne;
var displayPositionTwo;

for(var i = 0; i < oSettings.aiDisplay.length; i++) {
if(oSettings.aiDisplay[i] == domPositionOne) {
displayPositionOne = i;

if(oSettings.aiDisplay[i] == domPositionTwo) {
displayPositionTwo = i;

if(displayPositionOne < displayPositionTwo) {
for(var i = displayPositionOne; i <= displayPositionTwo; i++) {
else if(displayPositionTwo < displayPositionOne) {
for(var i = displayPositionTwo; i < displayPositionOne; i++) {

Is there a better way to get at the proper indices without using the oSettings.aiDisplay array?



  • allanallan Posts: 62,448Questions: 1Answers: 10,251 Site admin
    Hi Tony,

    Thanks very much for your post and kind words!

    The aiDisplay array is an array of integer indexes for the aoData array of objects. aiDisplay defines the order that the data should be drawn on the page after sorting / filtering etc - while aoData retains it's original ordering and all row information.

    The information which should actually be shown on the page is given by _iDisplayStart and it's friends. This is an index for aiDisplay, so you know which part of aiDisplay is on the page and _iDisplayLength will tell you where that ends.

    As such, one enhancement that I can see would be to replace "this.fnGetNodes(oSettings.aiDisplay[i])" with "oSetings.aoData[ oSettings.aiDisplay[i] ].nTr".

    Having said that, I think you will need to use aiDisplay index to translate the position on the page, into the position in aoData.

    Is this the information you were looking for, or are there any points I can clarify?

This discussion has been closed.