簡體   English   中英

添加行運行時如何在數據表中為td添加類?

[英]How to add class for td in datatable when add row runtime?

我想通過ajax獲取列表數據時將類添加到td

默認我的代碼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>

當我想在過濾后獲取列表數據時,我不知道如何添加類

$.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 ] } ] } ); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM