Archive

Archive for the ‘javascript’ Category

Flexigrid and Codeigniter with Advanced Searching (with example)

Original site http://flexigrid.eyeviewdesign.com

New Features:

– multiple searching criteria
– customization input type (text, select, or date)

All feedback, improvements, etc are very welcome.. 🙂

this is development version, you can download example here

Requirements:

– codeigniter 1.7.2 (Download)
– jquery-1.4.2.min.js
– jquery-ui.min.js
– flexigrid.js (added new custom script, include in download package)
– jquery-ui.css
– flexigrid.css

Install:

– extract .rar to CI folder

– open your contoller (ie: CI_Folder\system\application\controllers\flexigrid.php)

– configure flexigrid helper, and customize variable $colModel, example:

// $this->load->model('ajax_model');
// $records = $this->ajax_model->get_select_countries();
// $options is result set, generate from database
$options = Array (
 Array ( 'code' => 'AFG', 'name' => 'AFG' ),
 Array ( 'code' => 'DZA', 'name' => 'DZA' ),
 Array ( 'code' => 'ASM', 'name' => 'ASM' ),
 Array ( 'code' => 'AND', 'name' => 'AND' ),
 Array ( 'code' => 'AGO', 'name' => 'AGO' )
);

// create select option string format
foreach( $records as $v ) {
 $options .= $v['code'] .':'. $v['name'] . ';';
}
$options = substr($options, 0, -1);

/*
 * 0 - display name
 * 1 - width
 * 2 - sortable
 * 3 - align
 * 4 - searchable (2 -> yes and default, 1 -> yes, 0 -> no.)
 * 5 - option for search type and select option (type = text, date, select, default type is text)
 */
$colModel['id'] = array('ID',40,TRUE,'center',2);
$colModel['iso'] = array('ISO',40,TRUE,'center',0);
$colModel['name'] = array('Name',180,TRUE,'left',1);
$colModel['printable_name'] = array('Printable Name',120,TRUE,'left',1,'options' => array('type' => 'date'));
$colModel['iso3'] = array('ISO3',130, TRUE,'left',1, 'options' => array('type' => 'select', 'edit_options' => $options));
$colModel['numcode'] = array('Number Code',80, TRUE, 'right',1, 'options' => array('type' => 'select', 'edit_options' => ":All;AND:AND;KK:KK;RE:RE"));
$colModel['actions'] = array('Actions',80, FALSE, 'right',0);

Screenshoot:

Advertisements