Description: - DataTables is a powerful jQuery plugin for creating table listings and adding interactions to them. It provides searching, sorting and pagination without any configuration (usually used in admin panel's resources listing). - The backend support handled using "yajra/laravel-datatables-oracle" package. Backend Usage: - Create two functions in the resource controller, the first will return the view that contains the table. the second function responds to the ajax request coming from datatables ajax request (return the data to dill the table). -- example: public function index() // returns the view { return view('index'); } public function apiIndex() // responds to the ajax request { return DataTables::of(Model::all())->make(true); // use orderBy('sort') here in case you want to use the sort feature } // in case you use a sort feature public function sort{ $initial_sort = DB::select('select min(sort) as sort from {table} where id in('.implode(request('ids'), ',').')'); $i = $initial_sort[0]->sort; foreach (request('ids') as $id) { $data = Model::find($id); $data->sort = $i; $data->save(); $i++; } $msg['code'] = 1; $msg['message'] = 'Sorted successfully .'; return response()->json($msg); } // in case you use a delete multiple feature public function deleteMulti(Request $request) { foreach ($request->ids as $id) { Model::findOrFail($id)->delete(); } $msg['code'] = 1; $msg['message'] = 'Deleted successfully .'; return response()->json($msg); } - Note/ make sure to use "DataTables" class at the top of your controller Frontend Usage: - Create the table with id="data-table" without a body (
) as it will be filled by the datatable. - Add the attribute 'data-fill' to each# | Name | Image | // for external links columnChilds | // for internal links column (link from the database)Childs | // for input columnWhatever | // for sumitting input columnsWhatever | // for badges column"1,2,3" badge-success-fill="the word to type in the badge" // it's filled by the data-fill attribute by default badge-warning="same as above" badge-warning-fill="same as above" badge-danger="same as above" badge-danger-fill="same as above" badge-primary="same as above" badge-primary-fill="same as above" badge-info="same as above" badge-info-fill="same as above" badge-dark="same as above" badge-dark-fill="same as above" badge-light="same as above" badge-light-fill="same as above" badge-secondary="same as above" badge-secondary-fill="same as above" // note=> you can use badge-{type}="_others" to show this badge for non included values of the data-fill atribute in the other badges > Activation |
---|