In my application i am using datatables.net
var ticketHistoryDataTable = $('#ticketHistoryData').DataTable({
paging: false,
data: [],
searching: false,
columns: [
{ data: 'ticket_id' , title: "Ticket Number" },
{ data: 'transactiondate' , title: "Date" }
]
} );
I am adding data to the table following way:
var result_data = [{
ticket_id : '' ,
transactiondate : ''
},{
ticket_id : '' ,
transactiondate : ''
}];
ticketHistoryDataTable.clear().draw();
ticketHistoryDataTable.rows.add(result_data).draw();
result_data itself comes from jquery ajax get call to server. Retrieving the information may take some time, during which i want to display loading-processing message from datatable. What is correct way of doing this?
fn. dataTable. isDataTable() method provides the ability to check if a table node is already a DataTable or not. It can be accessed at any time, even before any DataTable has been created on the page.
This can be implemented by using the columns. data option of DataTables plugin API. The source returns an array of objects which is used to display the data in the HTML table.
You can use a loader in your html. Position should be same as the table. How to add a loader in HTML
or
Message container: <div id="MessageContainer"></div>
and
Apply some CSS styles for good look and feel.
$('#ticketHistoryData')
.on( 'draw.dt', function () {
console.log( 'Loading' );
//Here show the loader.
// $("#MessageContainer").html("Your Message while loading");
} )
.on( 'init.dt', function () {
console.log( 'Loaded' );
//Here hide the loader.
// $("#MessageContainer").html("Your Message while load Complete");
} )
.DataTable({
paging: false,
data: [],
searching: false,
columns: [
{ data: 'ticket_id' , title: "Ticket Number" },
{ data: 'transactiondate' , title: "Date" }
]
});
For more go through Events of DataTable
I think this might help you.
You might show message
You can use dom
option to show loading:
$('#example').dataTable( {
"dom": 'lrtip'
} );
"r" letter is related to show loading element.
For more information refer to this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With