I am encountering an issue with category sorting on my list of products. When I click on category sorting, it only shows the same category and product name repeatedly. All other sorting functions are working correctly, except for category sorting. I have tried changing category.name to category_name, but that causes category sorting to stop working altogether. I am at a loss as to why this is happening and how to resolve it.
Is there a way to use an Alias for the category name? And which file do I need to modify in order to make these changes?
var table = $('#product-table').DataTable({
processing: true,
serverSide: true,
bStateSave: true,
ordering: true,
dom: 'Bfrtip',
buttons:[],
ajax: '{{ URL::to('/admin/products.data') }}',
order: [[1, 'asc']],
columnDefs: [
{ orderable: false, targets: 0 }
],
columns: [
{data: 'edit', name: '', searchable:false},
{data: 'name', name: 'name'},
{data: 'product_code', name: 'product_code'},
{data: 'category_name', name: 'category.name'},
{data: 'impa_code', name: 'impa_code'},
{data: 'issa_code', name: 'issa_code'},
{data: 'status', name: 'is_active'}
],
"deferRender": true
});
**This is my blade file**
`<div class="row clearfix">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 m-t-50">
<div class="card">
<div class="body">
<table class="table table-striped table-hover dataTable" id="product-table">
<thead>
<tr>
<th class="col-sm-1"></th>
<th>{{ Lang::get('views.name') }}</th>
<th>{{ Lang::get('views.shipskart_code') }}</th>
<th>{{ Lang::get('views.category_name') }}</th>
<th>{{ Lang::get('views.impa_code') }}</th>
<th>{{ Lang::get('views.issa_code') }}</th>
<th>{{ Lang::get('views.status') }}</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>`
This is Controller
` ->editColumn('product_code', function ($product) {
$productCode = $product['product_code'];
return $productCode;
})
->addColumn('category_name', function ($product) {
return empty($product->category) ? 'N/A' : $product->category->name ;
})
->editColumn('impa_code', function ($product) {
$impaCode = $product->impa_code;
return $impaCode;
})
->editColumn('issa_code', function ($product) {
$issaCode = $product->issa_code;
return $issaCode;`