Exclude row(s) from sorting
Exclude row(s) from sorting

Hi guys,
Just found DataTables and implemented it on a table that is filled with data from Google Drive API. This list includes folders that MUST be at the top of the first page. Is there a way to exclude rows from sorting based on a class or something so they always show up first and are never sorted (the list comes sorted in alphabetical order which makes most sense for folders)
DataTables is doing exactly what it should do and it looks fine, I just need to exclude some rows from sorting, so they are always at the beginning of the list. Ideas?
Best regards,
Arnor Baldvinsson
Answers
You can't exclude rows from sorting. You can use Orthogonal data to affect how the ordering works. Without specifics its hard to say what exactly you need to do. If you have further questions please post specific info about your data and how you want it sorted.
Kevin
Hi Kevin,
Thanks for the reply. The table and the data is constructed with PHP. It's a list of file/folder names, file sizes and modification date. No matter what column is used to sort, the folder row(s) should always be at the top. I think the trick might be to just display those in a non-sortable table above the file list. That would eliminate the problem completely
Arnor
I would have to think about how to put this together but it may include using
orderFixed
to make sure the file/folder column is always sorted in a particular order. Might be able to use a hidden column (columns.visible
) that will contain 0 if the row has a folder or 1 if it has a file. Then with orderFixed the hidden column can be ordered, followed by the file/folder column. Then any user sorting.Might also need the use of
columns.orderData
to coordinate the ordering of the hidden column and the file/folder column.columns.render
can be used to populate the hidden column value based whether the row has a file or folder.Ok, after typing all that I figured I would try it:
http://live.datatables.net/lisahefo/1/edit
Is this what you are looking for?
Kevin
I mulled this over for a while before I realized the super-apparent solution. Create a first column named "sort" and populate it with integers, either asc or desc, and in your datatable declaration give that column this orderFixed:
Then in the columnDefs:
To populate the sort column, I wrote this little jQuery which executes just before the DataTable:
Thoughts?