Ways of passing data to datatable
Ways of passing data to datatable
imda123
Posts: 2Questions: 1Answers: 0
Hi everyone,
I have a jquery post like following, and which updates my existing datatable directly by injecting the data into the DOM like following:
$.post("/SearchCompetitor/Index", { username: _username }, StartLoading())
.done(function (data) {
if (data !== "UsernameError") {
var dbtb = $('<table />').append(data).find('#datatable-responsive').html();
$('#datatable-responsive').html(dbtb);
$('#datatable-responsive').dataTable({
"bDestroy": true
});
// This is where I re-create the table to display the data
}
else {
StopLoading();
ShowMessage("No user was found under: " + $('.txtSearch').val());
}
})
The "data" object holds the HTML of the table and what I'm trying to figure out here is how to pass the data directly into the datatable, instead of directly injecting it into the DOM like I'm doing right now:
var dbtb = $('<table />').append(data).find('#datatable-responsive').html();
$('#datatable-responsive').html(dbtb);
So my questions are:
- How to convert a C# List into a DBTable JSon acceptable format
- How to fill the data directly into the dbtable,without first injecting it into the DOM of the browser
Can someone help me out with this please?
This discussion has been closed.
Answers
P.S. The reason why I'd like to pass the data directly into the datatable first is because sometimes I could be injecting up to 5000 items into the DOM and my browser literally freezes and crashes, causing big performance issues for me.
This way if I passed the data directly into the datatable, DT would only inject xx (10-25-50-100) items into DOM at a time, if I'm correct?
Use
rows.add()
(orrow.add()
for a single row) to dynamically add rows to the DataTable. Using the API will also allow it to render the table more efficiently if you are using paging anddeferRender
, since not all nodes would need to be immediately created.Allan