jeudi 28 juillet 2016

How to filter for just one customer with yajra datatables

I have a customers table with each record linking to a customer contact:

http://localhost/untdchem/public/home/customers/contacts/1809

When I click on the above link, I want to display all the contacts for customer 1809 only in a datatable. I am trying to pass the customer ID somehow so I can filter for that customer only. I can fill the table with all the contacts but i want to just load for that customer.

Routes:

 //Customer Contacts
        Route::get('home/customers/contacts', ['as' => 'customers.contacts', 'uses' => 'CustomerContactsController@index']);
        Route::get('home/customers/contacts/data', ['as' => 'customers.contacts.data', 'uses' => 'CustomerContactsController@anyData']);

In my controller:

 public function index()
    {
        // GET request to index
        return view('pages.customer_contacts.index');
    }

 public function anyData()
    {


    $contacts = customer_contact::select(['CustContactFName','CustContactLName','CustContactCountryCode','CustContactExtension','CustContactPhone','CustContactEmail','CustContactType']);
    return Datatables::of($contacts)->make(true);     
    }

In my view:

<script>
$(function() {
    $('#customer-contacts-table').DataTable({
        processing: true,
        serverSide: true,

        ajax: '{!! route('customers.contacts.data') !!}',

        columns: [
            { data: 'CustContactFName', name: 'CustContactFName'},
            { data: 'CustContactLName', name: 'CustContactLName'},
            { data: 'CustContactCountryCode', name: 'CustContactCountryCode'},
            { data: 'CustContactExtension', name: 'CustContactExtension'},
            { data: 'CustContactPhone', name: 'CustContactPhone'},
            { data: 'CustContactEmail', name: 'CustContactEmail'},
            { data: 'CustContactType', name: 'CustContactType'}
            //{ data: 'action', name: 'action', orderable: false, searchable: false}
        ],
        order: [[0, "desc" ]]
    });


});
</script>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire