Detecting user interaction with the table.
Detecting user interaction with the table.
TJ14
Posts: 10Questions: 4Answers: 0
I am using the following datatable to display info at a pseudo-realtime rate. However I have run into issues when a user tries to interact with the table because the table redraws itself to quickly. Is there a way to detect interaction so that I can pause the interval until the interaction is complete?
<script>
$(document).ready(function () {
var table = $('#myDataTable').DataTable({
autoWidth: false,
bProcessing: true,
sAjaxSource: '@Url.Action("GetDropData", "Drops")',
processing: false,
"columns":
[
{ "width": "10%" },
{ "width": "50%" },
{ "width": "40%" }
]
});
setInterval(function () {
table.ajax.reload(null, false); // user paging is not reset on reload
}, 3000);
});
</script>
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
It depends what that interaction is. Do you mean sorting and the like? If so, use the
processing
event to know when DataTables is doing "stuff" so you can have it not reload at that point.Allan
The biggest problem I'm having is in conjunction to features in the responsive extension. Since the table is redrawing so fast, if the user is looking at the table on a small screen, the table redraws (because of the refresh) too quickly and any child record that is expanded snaps shut.
For this case, what you probably need to do is listen for
preXhr
to take a note of which rows are currently "open". Then inxhr
you can reopen them. not ideal, but at the moment DataTables considers the newly added rows to be completely new, hence why they are closed.I am considering making it so that rows which have the same ID are not considered to be new, but that will likely involve quite a lot of development work over all of the plug-ins and the core.
Allan
Allan, thank you so much for your help. If its not too much to ask could you write up a quick example. I'm a JS newb and have a hard time dealing with JS related issues unless I have some examples. If you can't that's ok too.
Sorry - a bit busy at the moment. I'll try to sometime next week, but can't promise with everything that is going on at the moment.
Allan