New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the filter & server mode now play nicely with the colReorder extension #532
Conversation
…nsion being loaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks!
// the table.colReorder.order() function will exist but throws error when called. | ||
// So it seems like the only way to know if colReorder is enabled or not is to | ||
// check the options. | ||
var colReorderEnabled = function() { return "colReorder" in options; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it have to be a function? I mean, does this work?
var colReorderEnabled = "colReorder" in options;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I used the non-function version at first and worked fine...
However, I overthinked that the options
may get changed somewhere else after the table being initialized... It's OK to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. It should not matter much. I'm fine to use a function here.
for (i = 0; i < data.length; ++i) { | ||
row = data[i].slice(); | ||
for (j = 0; j < order.length; ++j) data[i][j] = row[order[j]]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is a way to reorder the data on the server side. If there is, the implementation could be much easier (data[order]
in R instead of a nested loop in JS). Of course, it depends on whether we have the order information on the server side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the datatables
library doesn't send the reordered column info to the server by default. We need to register a callback in the event column-reorder
, which sends the info to the R side. If this method is better, I guess it's not very difficult to make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, let's just forget it. I'm not too concerned about the performance of the nested loops here since data
should typically be small enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the concern too... For the deep copy and nested loops... but as you said, it should be fine in the most cases.
Just a reminder to myself -- I need to update the docs at https://rstudio.github.io/DT/extensions.html |
Closes #531
Description
Before this PR, if the user enables the
colReorder
extension, the filter will return wrong results in the client mode. In the server processing mode, the table will be reverted to the original order whenever it gets re-drawed (i.e., triggered by the filter, search or the paginate button)The causes
datatable
is reordered but the filter functions itself is bind to the original order. So the wrong data gets filtered;After this PR
It should work for both cases.
The example