所以,這里是代碼
@extends('layouts.main')
@section('additional_css')
<link rel="stylesheet" href="{{ asset('css/leads.css') }}" />
<link rel="stylesheet" href="{{ asset('css/brand.css') }}" />
@endsection
@section('title', 'Brand (New Branch)')
@section('content')
<h1>Brand (New Branch)</h1>
<section class="section p-2">
<div class="col-md-12 py-3">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Brand Name</th>
<th>Instagram Account</th>
<th>Daily Sales</th>
<th>Location</th>
<th>Has Physical Store</th>
<th>Has Online Marketplace</th>
<th>Campaign Name</th>
<th>Channel Source</th>
<th>Tagging</th>
<th>Status</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</section>
@endsection
@section('additional_js')
<script src="{{ asset('vendors/dataTables/js/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('vendors/dataTables/js/dataTables.bootstrap4.min.js') }}"></script>
@endsection
@section('script')
<script>
$(document).ready(function() {
$('.table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '{{ route('leads.newBranch.paginate') }}',
dataType: 'json',
type: 'POST',
data: { _token: '{{ csrf_token() }}' }
},
columns: [
{ data: 'name', name: 'name' },
{ data: 'email', name: 'email' },
{ data: 'phone_number', name: 'phone_number'},
{ data: 'brand_name', name: 'brand_name'},
{ data: 'instagram_account', name: 'instagram_account'},
{ data: 'daily_sales', name: 'daily_sales'},
{ data: 'locations', name: 'locations'},
{ data: 'has_physical_outlet', name: 'has_physical_outlet'},
{ data: 'has_online_marketplace', name: 'has_online_marketplace'}
]
});
})
</script>
@endsection
如果運行代碼,則在 has_physical_outlet 和 has_online_marketplace 列中將顯示 1 或 0(資料取自表單)。在這種情況下,我想對其進行更改,以便在列中顯示“是”(如果資料本身為 1)或“否”(如果資料為 0)訊息。
由于我不熟悉 Ajax,有誰知道正確的方法?任何幫助表示贊賞,并提前感謝您
uj5u.com熱心網友回復:
您可以將渲染方法添加到特定的列選項
$(document).ready(function() {
$('.table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '{{ route('leads.newBranch.paginate') }}',
dataType: 'json',
type: 'POST',
data: { _token: '{{ csrf_token() }}' }
},
columns: [
{ data: 'name', name: 'name' },
{ data: 'email', name: 'email' },
{ data: 'phone_number', name: 'phone_number'},
{ data: 'brand_name', name: 'brand_name'},
{ data: 'instagram_account', name: 'instagram_account'},
{ data: 'daily_sales', name: 'daily_sales'},
{ data: 'locations', name: 'locations'},
{
data: 'has_physical_outlet',
name: 'has_physical_outlet',
render: function (data, type) {
if (type === 'display') {
return data ? 'yes' : 'no'
}
return data;
}
},
{
data: 'has_online_marketplace',
name: 'has_online_marketplace',
render: function (data, type) {
if (type === 'display') {
return data ? 'yes' : 'no'
}
return data;
}
}
]
});
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/503867.html
標籤:javascript jQuery 阿贾克斯 拉拉维尔
