gpt4 book ai didi

javascript - 添加行运行时时如何在数据表中为 td 添加类?

转载 作者:行者123 更新时间:2023-11-28 02:24:53 25 4
gpt4 key购买 nike

我想在通过ajax获取列表数据时将类添加到td

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",用于在运行时添加类

$('#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 ] }
]
} );

关于javascript - 添加行运行时时如何在数据表中为 td 添加类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54861697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com