When my sortablejs has an table of 2000+ records it gets realy slow and the page gives me the option to wait or close tab.
But this table is used by clients(in need of an good UX) so this cant happen to them.
I have the following code example:
var left = document.getElementById("left");
var right = document.getElementById("right");
generateTable(2000, left)
generateTable(10, right)
function generateTable(nOfRows, wrap) {
var newTable = document.createElement("table"),
tBody = newTable.createTBody(),
nOfColumns = 5,
row = generateRow(nOfColumns);
tBody.classList.add("sortable");
for (var i = 0; i < nOfRows; i++) {
tBody.appendChild(row.cloneNode(true));
}
(wrap.hasChildNodes() ? wrap.replaceChild : wrap.appendChild).call(wrap, newTable, wrap.children[0]);
}
function generateRow(n) {
var row = document.createElement("tr"),
text = document.createTextNode("cell");
for (var i = 0; i < n; i++) {
row.insertCell().appendChild(text.cloneNode(true));
}
return row.cloneNode(true);
}
Sortable.create(document.getElementsByClassName('sortable')[0], {
items: "tr",
group: '1',
animation: 100
});
Sortable.create(document.getElementsByClassName('sortable')[1], {
items: "tr",
group: '1',
animation: 100
});
<!-- Latest Sortable -->
<script src="/[email protected]/Sortable.min.js"></script>
<div id="left"></div>
<div id="right"></div>
When my sortablejs has an table of 2000+ records it gets realy slow and the page gives me the option to wait or close tab.
But this table is used by clients(in need of an good UX) so this cant happen to them.
I have the following code example:
var left = document.getElementById("left");
var right = document.getElementById("right");
generateTable(2000, left)
generateTable(10, right)
function generateTable(nOfRows, wrap) {
var newTable = document.createElement("table"),
tBody = newTable.createTBody(),
nOfColumns = 5,
row = generateRow(nOfColumns);
tBody.classList.add("sortable");
for (var i = 0; i < nOfRows; i++) {
tBody.appendChild(row.cloneNode(true));
}
(wrap.hasChildNodes() ? wrap.replaceChild : wrap.appendChild).call(wrap, newTable, wrap.children[0]);
}
function generateRow(n) {
var row = document.createElement("tr"),
text = document.createTextNode("cell");
for (var i = 0; i < n; i++) {
row.insertCell().appendChild(text.cloneNode(true));
}
return row.cloneNode(true);
}
Sortable.create(document.getElementsByClassName('sortable')[0], {
items: "tr",
group: '1',
animation: 100
});
Sortable.create(document.getElementsByClassName('sortable')[1], {
items: "tr",
group: '1',
animation: 100
});
<!-- Latest Sortable -->
<script src="https://cdn.jsdelivr/npm/[email protected]/Sortable.min.js"></script>
<div id="left"></div>
<div id="right"></div>
Share
Improve this question
edited Apr 1 at 10:19
StackByMe
6,52521 silver badges30 bronze badges
asked Apr 1 at 9:18
oelimoeoelimoe
4212 silver badges11 bronze badges
5
|
1 Answer
Reset to default 0To fix this issue you need to change the animation
setting to 0
of the sortable instance:
Sortable.create(document.getElementsByClassName('sortable')[0], {
items: "tr",
group: '1',
animation: 0
});
Sortable.create(document.getElementsByClassName('sortable')[1], {
items: "tr",
group: '1',
animation: 0
});
Related issue
a table of 2000+ records
that's the real problem. Don't do that – Panagiotis Kanavos Commented Apr 1 at 9:39<tr>.....</tr>
tags and all their content for the 1950 invisible objects. Most grids have a virtualization option – Panagiotis Kanavos Commented Apr 1 at 11:52