How can i scroll automatically down to a row in datatable
How can i scroll automatically down to a row in datatable
What i want to do is if it finds a row with corresponding it should scroll to that viewport of datatble. Currenlt the row is highlighted but its not scrolled to that place. Also, is there a way to search the value from all the data rather than just the current page data. Thanks in advance!!
function getQueryParameter(name) {
var urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
var logId = getQueryParameter('id');
setTimeout(function () {
if (logId) {
$('#assyntCx_Table tbody tr').each(function () {
var rowId = $(this).find('td:first').text().trim();
if (rowId === logId) {
$(this).find('td').css({ 'background-color': 'blue', 'color': '#000' });
table.scroller.toPosition(this);
}
});
}
}, 2000);
Answers
Since it looks like you are finding the row possibly you will want to use
row().scrollTo()
instead ofscroller.toPosition()
. See the docs for the differences.Use
rows().nodes()
to get all the nodes whether displayed on the current page or not.If you need further help please provide a simple test case with an example of your data and code so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin