I want add class to td when get list data by ajax
Default my code html
<tr>
<td>@fisrt.System_Code.Code</td>
<td>@fisrt.System_Code.Caption</td>
<td class="text-success">@string.Format("{0:N0}", maden)</td>
<td class="text-danger">@string.Format("{0:N0}", den)</td>
<td class="text-warning nrt-bd" dir="ltr">@string.Format("{0:N0}", maden - den)</td>
</tr>
When i want get list data after filtering , i dont know how to add class
$.ajax({
type: 'GET',
url: '/Record_Professor/Search_Budget/',
data: { from: from, to: to },
success: function (results) {
results.forEach(function (item) {
$('#table_id').dataTable().fnAddData([
item.Code,
item.Caption,
item.Maden,
item.Daeen,
item.Balance
]);
});
},
error: function (error) {
alert('error; ' + eval(error));
}
});
"className": "Classname", is used to add class at run time
$('#table_id').DataTable({ data: data2, "autoWidth": false, deferRender: true, pageLength: 10, responsive: true, scrollCollapse: true, select: { style: 'os', selector: 'td:first-child' }, "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ], "columnDefs": [{ "className": "Classname", "targets": [5,2,3,4,9,] }] });
$('#example').dataTable( { "columnDefs": [ { className: "my_class", "targets": [ 3 ] } ] } );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.