如何在数据表中添加一个额外的列来序列化杂货店中的数据

时间:2014-02-28 03:09:26

标签: javascript jquery codeigniter-2 flexigrid grocery-crud

我对杂货店非常感兴趣。我想添加一个额外的列,它将用于序列号,并且在搜索和分页时不会改变。我希望它像 JQgrid 。可能吗?请帮我。

1 个答案:

答案 0 :(得分:1)

尝试这种类型的代码

public function customers_management()
{

//This process is important to reset the last serial no...
$page = $this->input->get_post('page');
if($page == '') {
    $page=1;
} else {
    $per_page = $this->input->get_post('per_page');
    $start = ($page-1) * $per_page;
    $this->session->set_userdata('lastSerial', $start);
}

$this->load->library('grocery_crud_with_tab');
$crud = new grocery_crud_with_tab();

$crud->set_table('customers');
$crud->columns('serial_no', 'customerName','contactLastName','phone','city','country','salesRepEmployeeNumber','creditLimit');
$crud->display_as('salesRepEmployeeNumber','from Employeer')
->display_as('customerName','Name')
->display_as('contactLastName','Last Name');
$crud->set_subject('Customer');
$crud->set_relation('salesRepEmployeeNumber','employees','lastName');
$crud->callback_column('serial_no', array($this, 'generateSerialNo'));

$crud->set_tab('default',  'Customer Details', array('customerName', 'salesRepEmployeeNumber', 'creditLimit'));
$crud->set_tab('contact', 'Customer Contact', array('contactLastName', 'contactFirstName', 'phone'));
$crud->set_tab('address', 'Customer Address', array('addressLine1', 'addressLine2', 'city', 'state', 'postalCode', 'country'));

//This is written exclusively because the jquery ui provided with this version of grocery crud dose not posses the tabs function.. hence had to 
//set the same from the cloud.
$crud->unset_jquery_ui();
$crud->unset_jquery();
$crud->set_css('//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css', false);
$crud->set_js('//code.jquery.com/jquery-1.11.0.min.js', false);
$crud->set_js('//code.jquery.com/ui/1.10.4/jquery-ui.js', false);

$output = $crud->render();
$this->_example_output($output);
}

 function generateSerialNo() {
if($this->session->userdata('lastSerial') == '') {
    $this->session->set_userdata('lastSerial', 0);
    $this->session->set_userdata('lastPage', 1);
    $lastSerial = 0;
} else {
    $lastSerial = $this->session->userdata('lastSerial');
}
$lastSerial++;
$page = $this->input->post('page');
if($page != '') {
    $this->session->set_userdata('lastPage', $page);
} else {
    $this->session->set_userdata('lastPage', 1);
}
$this->session->set_userdata('lastSerial', $lastSerial);

return $lastSerial;
}