How to highlight rows (when some not currently displayed by DataTables)?

How to highlight rows (when some not currently displayed by DataTables)?

airandfingersairandfingers Posts: 30Questions: 0Answers: 0
edited October 2011 in General
I'm trying to use jQuery UI's effect() method to highlight rows when they're inserted or modified. I was doing this with my raw HTML tables, and I want to know what the best way to do it with DataTables is.

The problem I'm running into is demonstrated here:
http://live.datatables.net/uxadaw/5/edit
Note that this successfully highlights the first four rows of the table (the original table, not the auto-sorted DataTable), then fails when attempting to highlight a row that's not currently displayed by DataTables.

Is there a way to check if a row is currently displayed by DataTables? That should solve this for me.

Also, what's the recommended method for obtaining the row that fnGetPosition and fnUpdate require as an argument? In my code I've been storing off a reference to this row as follows:
[code]
var added = $table.fnAddData(row_values);
added.length == 1 || alert('Should never happen! Impossible!');
var index = added[0],
$row = $($table.fnGetNodes(index));
[/code]
This is fine for my purposes, but it's been trickier to get a reference to a row if I don't store it at add-time.

Cheers,
Aaron

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Hi Aaron,

    Thanks again for the JSBin example! That is a massive help to me for understanding and diagnosing the problem. In this case what we need to do is make use of one of the plug-in API methods to get the display only TR elements. The plug-in fnGetDisplayNodes ( http://datatables.net/plug-ins/api#fnGetDisplayNodes ) does this, and I've modified your example with that plug-in here: http://live.datatables.net/uxadaw/7/edit .

    Regards,
    Allan
  • airandfingersairandfingers Posts: 30Questions: 0Answers: 0
    edited October 2011
    (Removed because I posted to the wrong discussion @@)
  • airandfingersairandfingers Posts: 30Questions: 0Answers: 0
    Thanks for that reference. I have this working in JSBin, and havent' had a chance to test my modified code on my system. I'm just measuring the value of
    $.inArray(raw_row, $table.fnGetDisplayNodes()), and not trying to highlight the row if this check returns -1. See
    http://live.datatables.net/uxadaw/11/edit

    Will this work fine with the Scroller? That is, what value does fnGetDisplayNodes() return in the context of a table with Scroller?

    Final question for now: What's the difference between Scroller and the infinite scrolling enabled by setting bScrollInfinite?

    Thanks,
    Aaron
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    > Will this work fine with the Scroller?

    Yes - the way Scroller works is that is actually makes use of the paging system in DataTables, so if it works with paging enabled, it will work with Scroller.

    > What's the difference between Scroller and the infinite scrolling enabled by setting bScrollInfinite?

    Basically Scroller depreciates infinite scrolling - Scroller has all the advantages of infinite scrolling, but also shows the scroll bar positioning accurately for the full data set. There is an article detailing exactly how Scroller works, and its benefits, here: http://datatables.net/blog/Introducing_Scroller_-_Virtual_Scrolling_for_DataTables .

    Regards,
    Allan
This discussion has been closed.