Как добавить класс для TD в Dataatable, когда добавить время выполнения строки? - PullRequest
0 голосов
/ 25 февраля 2019

Я хочу добавить класс в td, когда получаю данные списка по ajax

По умолчанию мой код 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));
                }
            });

1 Ответ

0 голосов
/ 25 февраля 2019

"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 ] }
  ]
} );
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...