Coding

How do I define a data property for a column that is not from the ajax data source?

ajax data source

Story Highlights
  • How to get the data in AJAX?
  • What is AJAX in DataTables?
  • How to send data with AJAX?
  • How to use data table in AJAX?

If you want to define a data property for a column that is not from the Ajax data source, you can use the columns.data option in jQuery DataTables.

Here is an example of how you can define a data property for a column that is not from the Ajax data source:

$(document).ready(function() {
$(‘#example’).DataTable( {
“ajax”: “data.json”,
“columns”: [
{ “data”: “name” },
{ “data”: “position” },
{ “data”: “office” },
{ “data”: “salary” },
{ “data”: “custom_data”,
“render”: function ( data, type, full, meta ) {
// Define your custom data property here
var custom_data = “Custom data for row “+meta.row;
return custom_data;
}
}
] } );
} );
In this example, the data property for the first four columns is defined to be from the Ajax data source, while the data property for the fifth column is defined to be a custom data property that is generated using a function passed to the render option. In this function, you can define your custom data property based on any logic or calculations you need, and return it to be displayed in the table.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button