• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DataTables 1.10 > Library

#11
Yes, it is really handled through the DataTables JS library.  Here is an example of the `columns` option in the JavaScript setup for DataTables.


Code:
       columns: [
      {
        data: null,
        defaultContent: '<span class="btn btn-info btn-edit btn-xs">Edit</span> ',
           orderable: false,
           searchable: false
       },
           {   data: "st_name"  },
           { data: "st_address" },
           { data: "st_city" },
       { data: "st_state" },
       { data: "st_zip"  },
       
       { data: "st_phone" }
       ]


Then you can put a event listener on the button using jQuery:


Code:
    $("#storetable tbody").on("click", ".btn-edit", function() {
  var tr = $(this).closest("tr");
    var recordId = tr.attr("id");

//call some ajax to edit / delete record
// ....
   });


Make sure you specify the db column to map to the table row id in the Datatable CodeIgniter lib.


PHP Code:
$this -> load -> library('Datatable', array('model' => 'store_dt''rowIdCol' => 'store_no')); 

Here is the DataTable documentation for the options on the columns.
Reply

#12
(04-13-2015, 07:13 AM)zepernick Wrote: Yes, it is really handled through the DataTables JS library.  Here is an example of the `columns` option in the JavaScript setup for DataTables.



Code:
       columns: [
      {
        data: null,
        defaultContent: '<span class="btn btn-info btn-edit btn-xs">Edit</span> ',
           orderable: false,
           searchable: false
       },
           {   data: "st_name"  },
           { data: "st_address" },
           { data: "st_city" },
       { data: "st_state" },
       { data: "st_zip"  },
       
       { data: "st_phone" }
       ]


Then you can put a event listener on the button using jQuery:



Code:
    $("#storetable tbody").on("click", ".btn-edit", function() {
  var tr = $(this).closest("tr");
    var recordId = tr.attr("id");

//call some ajax to edit / delete record
// ....
   });


Make sure you specify the db column to map to the table row id in the Datatable CodeIgniter lib.



PHP Code:
$this -> load -> library('Datatable', array('model' => 'store_dt''rowIdCol' => 'store_no')); 

Here is the DataTable documentation for the options on the columns.

hi zepernick.. im still newbie on codeigniter.
can u give online demo like your previous sample .....
Reply

#13
hi zepernick.. can u give online example. coz im still newbie ..
* example for datatables with edit or delete button for each record.
Reply

#14
I wrote a tutorial how to integrate DataTables and Editor in CodeIgniter 3. Maybe it is of any help to you, see http://ci.dubbel16.nl
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.