⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

how to add a serial column to list view



MD Rahat Islam Khan
  • profile picture
  • Member

Posted 27 February 2014 - 18:36 PM

i want to add a extra serial

column at the first column and it will not change on search.i want it like jqgrid.please help me


connard
  • profile picture
  • Member

Posted 27 February 2014 - 22:03 PM

Hey I have same problem, I think it's a limitation when you have something else in columns than a 1-N or N-N relation. you can't sort by clicking on column or search in these fields.


Amit Shah
  • profile picture
  • Member

Posted 28 February 2014 - 08:31 AM

Well.. i should really thank you ppl as for bringing up this wonderful requirement. This gave me a bit of challenge to solve it and here is the solution for the same.

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;
}

One thing - you need to be careful with this - The search functionality usually tries to use every column in the display to search the data / content through .. but this is a custom field and cannot be part of the query ... so be sure to patch your default library using the patch provided in my prior post.

 

Happy GCing:)


Quality Analyst
  • profile picture
  • Member

Posted 05 March 2014 - 13:17 PM

great


MD Rahat Islam Khan
  • profile picture
  • Member

Posted 22 March 2014 - 16:59 PM

$this->load->library('grocery_crud_with_tab')

its giving me an error.unable to load


Amit Shah
  • profile picture
  • Member

Posted 23 March 2014 - 04:25 AM

sorry dont load grocery_crud_with tab.. this must have been some code where i just picked from my project and pasted.. just use $this->load-library(grocery_crud)