how integrate if i don't know length of my data
how integrate if i don't know length of my data
zeing
Posts: 9Questions: 3Answers: 0
i get data from ajax post request to api
how integrate if i don't know length of my data ????
i want to lazy loading when my transaction data is very big and my api support lazy loading .
this is my js to post to api then api will get respond data to me
table_redeem = $('#table_redeem').DataTable({
deferRender: true,
scrollY: 200,
scrollCollapse: true,
scroller: true,
"ajax": function (data, callback, settings) {
var data = {
"cmd": "getTransaction",
"firstitemindex": 1, //if set firstitemindex 1 and itemperpage 10 , will get data[0]-data[9]
"itemperpage": 100, /if set firstitemindex 11 and itemperpage 15 , will get data[10]-data[24]
"order": "asc",
}
data = JSON.stringify(data)
$.ajax({
url: config.api,
crossDomain: false,
contentType: "application/json",
dataType: 'json',
type: 'POST',
data: data,
success: function (data) {
if (!data.error) {//Command SUCCESS
arrTransRedeem = data
} else {
console.log('Handel error later !');
}
},
error: function (xhr, status, err) { // server doesn't respone
console.error('Contact backend error');
console.log(xhr, status, err);
},
complete: function () {
callback({data: arrTransRedeem});
}
});
},
"columns": [
{"data": "trx"}, // <-- which values to use inside object
{"data": "description"},
{"data": "subscribername"},
{"data": "productitemname"},
{"data": "qty"},
{"data": "amount"},
{
"data": "operator", "render": function (data, type, full, meta) {
return "YAYA"
}
},
{
"data": "branch", "render": function (data, type, full, meta) {
return "";
}
},
{
"data": "requestdate","width":"10%", "render": function (data, type, full, meta) {
return formatDate2(data)
}
},
{
"data": "status", "render": function (data, type, full, meta) {
if (data == 0)
return "<span class='label label-success'>Success</span>"
else if (data == 2)
return "<span class='label label-default'>Cancel</span>"
else
return "<span class='label label-danger'>Failed</span>"
}
},
{
"orderable": false, "data": "id", "width": "5%", "render": function (data, type, full, meta) {
return "<button type='button' class='btn btn-action' data-trx=" + full.trx + " data-toggle='modal' data-target='#modalTransaction' id='trans_detail'> <i class='fa fa-search'></i> </button>"
}
}
]
});
This discussion has been closed.
Answers
I'm afraid there is no option to not specify the size of the data. You could consider using server-side processing if you know the number of rows, and that allows lazy loading.
But there is no way to not specify the total number of rows - consider for example how would Scroller know how many rows to allow scrolling to if the number of rows was undefined.
Allan
can i scroll down incessant when i still don't know about my length of data ?
can give me example about it ?
eing
thank you
okay i can get total of transaction by
db.collection.count() .
Can i use server-side processing ?