Add Rows after Order.
Add Rows after Order.
boraerel
Posts: 4Questions: 2Answers: 0
Hi,
I have a problem. I want to add row after reorder. But when i add row after order, it doesnt fit.
My code;
let data = [];
data.push(
[
{ desc: 'Description' ,orderId:0 },
{ bid: '', orderId: 1 },
{ ask: '', orderId: 2 }
]
);
table = ('#test').DataTable({
paging: false,
searching: true,
info: false,
order: [],
autoWidth: false,
colReorder: true,
destroy: true,
createdRow: function (row, data, dataIndex) {
$.each($('td', row), function (colIndex) {
$(this).attr('data-orderid', colIndex);
if (!$('.switch input').prop('checked')) {
if (colIndex == 3 || colIndex == 5 || colIndex == 6 || colIndex == 7 || colIndex == 8 || colIndex == 9 || colIndex == 10)
$(this).addClass("d-none");
}
$(this).attr('data-id', Object.keys(data[colIndex])[0]);
});
},
columnDefs: [
{
data: "desc",
targets: "desc",
render: function (data, type, full, meta) {
return 'desc';
}
}, {
data: "bid",
targets: "bid",
type: 'numeric',
render: function (data, type, full, meta) {
return '<span class="color-red font-weight-bold">' + formatNumber(data, 2) + '</span>';
}
}
, {
data: "ask",
targets: "ask",
type: 'numeric',
render: function (data, type, full, meta) {
return '<span class="color-green font-weight-bold">' + formatNumber(data, 2) + '</span>';
}
}
});
table.clear().rows.add(data).draw();
I need to add rows like this way.
When I put the "ask" column at position 0 and then want to add new rows, it is not based on the name in the data source.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
You've got
order: [],
- so there is no ordering in the DataTable when it initialises. Set theorder
parameter to whatever column it is that you want to order on (I'm not actually sure - theask
column?).Allan