Fixed / Persistent / Sticky Row - regardless to Filtering & Ordering

Fixed / Persistent / Sticky Row - regardless to Filtering & Ordering

Zerix2889Zerix2889 Posts: 4Questions: 1Answers: 0
edited July 2015 in Free community support

Hello,

First of all, hopefully my english is fine, it's not my native language so thanks if you decide to help me anyway.

I need to program a table which will be a little bit complex, most of the parts (multi filter with selects, ...) works just fine, so big hand to the DataTables team, it's a very cool Library!

Now I'm going to hit a wall, I don't know how to add this functionality even it's maybe not a usual one.

I need to "fix" selected rows on the top of the table, I don't want to create another table on the same site and just move the items to the other one (in a further step this is needed too but once the items are selected and the next step is taken)

As I mentioned in the subject those "fixed" or "persistent" rows should be not affected by Filtering or Ordering (maybe ordering within all fixed rows will be fine)

What I already tried?

  • Create another tbody/thead/tfoot and copy the element to this one, the problem is I'm going to lose DataTables functionality so there are some hidden columns if I'm going to display a new column the data won't be rendered since it's not in the usual tbody (with the right data set)

  • Implement drawCallback and try to keep this row on the top, but the filter will still remove the fixed row if it's not passing through the filter criteria..

  • Use aaSortingFixed and a hidden Column.. like mentioned here: http://datatables.net/forums/discussion/1441/fixed-row
    (Still problem with the filter/search criteria)

Write own filter? I'm not sure, but I need to still have some filters affected on non-sticky rows..

Or is there any possibility to show certain rows - independent from their filters - so I can just select all fixed rows and make them visible after the filter done and the table is drawn.

Thanks in advance and hopefully it wasn't too much text..
Best regards, Christian!

P.S.: If needed I'm going to write a test build, but I'm not sure since it's more an "request" for a new feature, ..

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    Can you just put your row in the header? Would that not meet your requirements?

    The alternatively is probably to inject it into the table using drawCallback as you suggest.

    Allan

  • Zerix2889Zerix2889 Posts: 4Questions: 1Answers: 0

    I'm not sure if it's just limited to my knowledge but I've the problem that all rows need to be attached to the normal tbody first.

    After someone click on an row it will be moved to the top. So your idea by taking the row and attach it to the thead sounds great. But as far as I know the next time DataTable redrawn it will be removed.. or if a hidden column will be shown DataTables will miss to add the additional data to this row.

    Or is there any function to move an row from tbody to thead internally within DataTables? Because I think to move it in DOM isn't a good idea in addition to all the internal stuff like filtering, column hiding and so on..

    Another way to make this happen is just to reintialize the DataTable (Destroy it, move the tr element to thead and init it again), but I think this will end up in a short-initialize time and the user will see a very large table or it will be hidden for a short time.

    Thanks for your fast reply! Sorry for late response, I just wanted to keep my head free on weeked. :)

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    After someone click on an row it will be moved to the top.

    I didn't know that. In which case, yes I retract my suggestion of putting the row in the header.

    You would indeed need to use the drawCallback to "fix" it to the top of the table body. You might run into a few issues with paging, but the other other option is to provide custom ordering functions.

    Allan

  • Zerix2889Zerix2889 Posts: 4Questions: 1Answers: 0

    Then I'm going to have problems with the filter, as I mentioned in the first post, it's not easy to focus on all those points at once and don't get in trouble with them.

    I think there is no easy-way for this as long as I don't reinitialize the whole table.. it's a little bit tricky to "disable" ordering or filtering for specific rows to highlight them. But I understand that DataTables won't have everything built into the core, it still needs to be very reliable.

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin
    Answer ✓

    There is one other option I've just though of. Have a hidden column that is value 1 or 0. Then use orderFixed to have DataTables perform ordering on that column before the other columns (user defined sorting).

    When you click on a row, have it change to value 1 for the hidden column (and any other row that was previously value 1, change it back to 0). That way the sorting will force that row to the top!

    Allan

  • Zerix2889Zerix2889 Posts: 4Questions: 1Answers: 0
    edited July 2015

    This works just fine so far, update the hidden "sortFixed" cell to value 1 if selected and it will be sorted just right by the 'orderFixed': [Index, 'desc'], option.

    But still the problem with the filtering it will be hidden if I input some filters.

    Is there any option to add a custom filter which will make the row always visible if the sortFixed or a specific cell has the value "1".. regardless of the other filters? Think this would be a great possibility so there is some sort of multiple Filters or fixedFilters which will always have highest priority..

    Maybe I'm going to build a test table setup tomorrow so it's easier to understand my request.. But I'm very thankful for your input!

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    Hmmm - yes. I'd forgotten about the filters. No, there is no way around that would providing custom filtering and only custom filtering. Sorry!

    Allan

This discussion has been closed.