how to keep scroller fixed
how to keep scroller fixed
hello ,all ,i create a datatable with the following codes
table = $("#Table").on('key-focus', function (e, datatable, cell) {
console.log("the key pressed and do something……")
}).DataTable({
keys: true,
scrollY: "200px",
autoWidth: false,
deferRender: true,
paging: true,
scroller: true,
scrollX: true,
responsive: false,
order : [
[5,"asc"],
[4,"desc"],
[2,"desc"],
[3,"asc"],
]
columns: [{
title: 'column1',
orderable: false,
width: "100%",
render: function (data, type, valueOfElement, meta) {
return data = '……';
}
}]
});
and i will add a lot of data into the datatable after init,so the scroller will scroll to another position and the data i am browsing or processing will disappeared in the visible area. i wanna know how to keep the relative position of the visible rows will not change,thank you
Answers
Are you saying you are using
row.add()
orrows.add()
to add the rows? If so try passingfalse
intodraw()
. For example:See the
draw()
docs for all the options. If this doesn't help then please provide more details of how you are adding the rows. Better is a link to your page or a test case replicating the issue so we can help debug.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
yes, i use row.add().draw(false) to add rows.but it also will scroll slowly from top to bottom. because one of orders is desc by timestamps.because my code is not publish yet,so i can not link to it
I created an example where the table doesn't scroll when adding rows:
https://live.datatables.net/dodobuge/4/edit
It stays on the same page (no scrolling), you can see this by watching the info element, ie
Showing 19 to 24 of 570 entries
, each time you click the add rows.Can you update the test case to show the issue you are trying to solve?
Kevin
yes , i've edited it ,you move the scroller to some posiotion at center(not at the start), you will see the scroller is scroll by itself when click add rows some times
https://live.datatables.net/dodobuge/5/edit
even if in https://live.datatables.net/dodobuge/5/edit, the info element is not change too, but i wanna the fixed one is the selected item not the index range
I'm really confused. Loading Kevin's example, if I:
Can you give step by step instructions on how to reproduce the issue?
Allan
I would expect that. We don't attempt to keep the selected row in view (indeed, the user might already have scrolled away from it). The
scrollTop
just stays the same.If you need to have the selected row stay in view, you'd need to find the position of the row in the table after having inserted the rows (
row().node()
and get its offset) and then change the scrollTop of the container. That isn't something we'd put into DataTables core I don't think.Allan