Я пытаюсь добавить атрибут data-foo
в каждую строку моего DataTable.Мне нужен этот атрибут для сортировки данных, однако я попробовал следующее, но он не добавляет определенный атрибут
cx.common.data.cxAdminDataTables.EbFaqCategory = $CxRecordsTable.cxAdminDataTable({
ajaxUrl: '<?php echo $this->CxHelper->Route('eb-admin-get-general-faq-categories')?>',
// Per-row function to iterate cells
"createdRow": function (row, data, rowIndex) {
// Per-cell function to do whatever needed with cells
$.each($('tr', row), function (colIndex) {
// For example, adding data-* attributes to the cell
$(this).attr('data-foo', "bar");
});
},
columns: [
cx.common.admin.tableEditColumn('id', { delete: true }),
{ data: 'category_name' },
{ data: 'faq_order' },
cx.common.admin.tableDateColumn('date_created')
]
});
Код моего просмотра:
<table id="cx-records-table" class="table table-striped table-bordered faq-categories-table" width="100%">
<thead>
<tr>
<th></th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Name">
</th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Order">
</th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Date Created">
</th>
</tr>
<tr>
<th></th>
<th class="all">Name</th>
<th class="all">Order</th>
<th class="all">Date Created</th>
</tr>
</thead>
<tbody></tbody>
</table>
Js:
var $sortable = $( ".faq-categories-table > tbody" );
$sortable.sortable({
stop: function ( event, ui ) {
var parameters = $sortable.sortable( "toArray");
console.log(parameters);
$.ajax({
url: '<?php echo $this->CxHelper->Route('eb-admin-change-general-faq-category-order')?>',
type: 'POST',
data: { value: parameters },
success: function (data) {
cx.common.data.cxAdminDataTables.EbFaqCategory.cxAdminDataTable("reloadAjax");
}
});
}
});