This example show badges rendered next to the position content dynamically. This technique can be useful for adding links, assigning colours based on content rules and any other form of text manipulation you require.
var status ={1:{"title":"Pending","state":"primary"},2:{"title":"Delivered","state":"danger"},3:{"title":"Canceled","state":"primary"},4:{"title":"Success","state":"success"},5:{"title":"Info","state":"info"},6:{"title":"Danger","state":"danger"},7:{"title":"Warning","state":"warning"},};$("#kt_datatable_example_1").DataTable({"columnDefs":[{// The `data` parameter refers to the data for the cell (defined by the// `data` option, which defaults to the column being worked with, in// this case `data: 0`."render":function(data, type, row){var index = KTUtil.getRandomInt(1,7);return data +'<span class="ms-2 badge badge-light-'+ status[index]['state']+' fw-bold">'+ status[index]['title']+'</span>';},"targets":1}]});
Complex Header
This example shows multiple layers of heading rows. This technique can be useful for large scale data types that requires a single title heading to be split into multiple columns for better data readability.
This example shows the datatable footer dynamically calculating the sum of a specified column. This technique can be useful for summing up columns for balance sheets or financial data.
$("#kt_datatable_example_4").DataTable({"footerCallback":function(row, data, start, end, display){var api =this.api(),
data;// Remove the formatting to get integer data for summationvarintVal=function(i){returntypeof i ==="string"?
i.replace(/[\$,]/g,"")*1:typeof i ==="number"?
i :0;};// Total over all pagesvar total = api
.column(4).data().reduce(function(a, b){returnintVal(a)+intVal(b);},0);// Total over this pagevar pageTotal = api
.column(4,{
page:"current"}).data().reduce(function(a, b){returnintVal(a)+intVal(b);},0);// Update footer$(api.column(4).footer()).html("$"+ pageTotal +" ( $"+ total +" total)");}});
DOM Positioning
When customising DataTables for your own usage, you might find that the default position of the feature elements (filter input etc) is not quite to your liking. For more info please check
DOM positioningdocumentation.