How To Role Callback Business Office Inwards Ignited Datatables ?

I did roughly query on jQuery datatables wrapper [IgnitedDatatables] as well as made it working on a projection to charge huge data. One work where i stuck was how to usage callback business office on edit columns. After several hours of try, i fixed it. Below is the solution on how i fixed it.

This post is non virtually how to usage Ignited Datatables. I assume that yous cause got working Ignited Datatables .

This instance is taken from https://github.com/n1crack/IgnitedDatatables-php-library/blob/master/examples/callback_functions/ajax.php
 $this->datatables->select('customer_id, first_name, last_name, email') ->from('customer') ->add_column('edit', 'Edit', 'customer_id') ->add_column('delete', 'Delete', 'customer_id') ->edit_column('email', '$1', strtolower('email')) // php functions ->edit_column('email', '$1', $this->custom_email('email'))  // custom functions ->edit_column('first_name', '$1', $this->fix_first_name('first_name'));  echo $this->datatables->generate(); 
 // Callback Functions business office custom_email($val) {   provide substr($val, 0, 3) . '..' . strstr($val, "@"); }   business office fix_first_name($val) {   provide ucwords(strtolower($val)); } 

How to usage callback business office properly inwards an ignited datatables is shown below.

The inwards a higher house solution (custom edit_column callback business office ) will non work for example, if yous wishing to cheque the condition of the user as well as wishing to display active or inactive condition instead of one or 0.

I simply wishing to enjoin yous that yous cause got to put callback functions inwards the Codeigniter helper file as well as not inwards the same controller. Influenza A virus subtype H5N1 CodeIgniter helper file is a PHP file amongst multiple functions. It is non a class.
To arrive work. yous cause got to charge the helper file ($this->load->helper('My_datatable_helper')) earlier $this->datatables->generate() method.

Do think that callbacks are made within a library file which of course of didactics has no straight access to which controller uses it. Therefore, it is much easier or actually, simply possible (from a library betoken of view) to usage helpers instead for their callbacks.
 /* Controller */  $this->load->helper('My_datatable_helper');  //load earlier generate business office ->edit_column('status', '$1', 'check_status($status)')  // custom callback functions echo $this->datatables->generate(); 
The controller has check_status($status) callback business office to display ACTIVE OR INACTIVE depending on condition (0 or one inwards the mysql database). In club to accomplish that, yous take away to exercise a Codeigniter helper file as well as relieve this to 'application/helpers/' directory. I created 'MY_datatable_helper.php' as well as house a business office inside. The check_status business office checks the condition variable as well as provide Active, it is one otherwise Inactive. Below is the helper file:
 /* MY_datatable_helper.php*/  <?php if ( ! defined('BASEPATH')) exit('No straight script access allowed');  /**  *  edit_column callback business office inwards Codeigniter (Ignited Datatables) * * Grabs a value from the edit_column champaign for the specified champaign then yous tin * provide the desired value.   * * @access   world * @return   mixed */  if ( ! function_exists('check_status')) {     business office check_status($status = '')     {         provide ($status == 1) ? 'Active' : 'Inactive';     }    }  /* End of file MY_datatable_helper.php */ /* Location: ./application/helpers/MY_datatable_helper.php */    
All credit goes to codeigniter Ignited-Datatables library. You tin download the library from https://github.com/IgnitedDatatables/Ignited-Datatables


Sumber http://developer-paradize.blogspot.com

Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?