Is there a way to delete rows after doing a sort?
Is there a way to delete rows after doing a sort?
I have a DataTable where I've used the rowGroup
extension in order to group by a certain value. Within the rowGroup I used the endRender
option to have a grouping "summary" row (like in this example).
What I want to achieve is if the table is sorted by any column, I want to get rid of that "summary" row. Otherwise the table is weirdly littered with it, and it makes no sense anymore in the context of the new sort. So, I tried to do an order event, like so (assume all the summary rows to remove have a .summary-row
class so I can easily grab them):
$('#my-table').on( 'order.dt', function () { my_table.row('.summary-row').remove().draw(); });
This does not work and results in stack level too deep when I call draw()
. Can anyone help me accomplish this?
Thanks!
This question has an accepted answers - jump to answer
Answers
You can use
rowGroup().disable()
to disable row grouping in theorder
event.Kevin
Thanks. I must be missing some js fundamental here, because I keep ending up at
Uncaught RangeError: Maximum call stack size exceeded
.So I have my datatable set up:
var my_table = $("#my-table").DataTable({ ...all the options... });
Then right under that I have the code I want to run upon ordering:
$('#my-table').on( 'order.dt', function () {
my_table.rowGroup().disable().draw();
});
That results in the error when I order by any column.
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Sorry, the
draw()
is causing the problem. Instead of using$('#my-table').on(...)
you will want to useone()
, for example:http://live.datatables.net/woboyeze/1/edit
Kevin
You rock @kthorngren, that did it!