⚠ 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

Export table data



newbie2005
  • profile picture
  • Member

Posted 11 June 2014 - 16:53 PM

Assume display table has 10 fields, but crud->columns shown 4 fields, if select EXPORT function, it will export 4 fields data which define in crud->columns.

How to set export all 10 fields data ?


Amit Shah
  • profile picture
  • Member

Posted 12 June 2014 - 16:46 PM

Well .. do a check on the action type.. if its not for export - set the columns else just avoid / ignore it.


newbie2005
  • profile picture
  • Member

Posted 13 June 2014 - 05:06 AM

I know the program has curd->set_columns("name","address"), but I can't found function such as crud->allcolumns()


Amit Shah
  • profile picture
  • Member

Posted 13 June 2014 - 08:13 AM

my friend...

use the following

http://www.grocerycrud.com/documentation/options_functions/getState

if the state is not export / print..

set the columns .. else dont set the columns.


vgsangiuliano
  • profile picture
  • Member

Posted 29 January 2015 - 16:56 PM

Hi Amit,
I am trying to follow your hints.
My code is
 
public function _employees_management($data = null)
{
                        $crud = new grocery_CRUD();
                        $crud->set_theme('datatables');
$crud->set_table('employees');
                        $state = $crud->getState();
                        if ($state != 'export')
                            {
                             $crud->columns('Name','Surname');
                            }
                        $output = $crud->render();
$this->_example_output($output);
}
 
List view is showing correctly just two columns specified.
When I click on export I get a csv file with just the two columns and not the whole table as I would like to get.
 
Do you have any suggestion?
Many thanks
 
Mirko

Amit Shah
  • profile picture
  • Member

Posted 30 January 2015 - 05:05 AM

well. did u try to checkout what is the result for if u try to set columns exclusively for state - export!!?? if that works.. which it technically should .. then its great.. cuz even i do it that same way - ...set the columns i want in export.


vgsangiuliano
  • profile picture
  • Member

Posted 30 January 2015 - 16:41 PM

Amit thanks for your help.

I tried to have a method as simpler as possible

public function test()
{
                        $crud = new grocery_CRUD();
                        $crud->set_theme('datatables');
                        $crud->set_table('employees');
                        $state = $crud->getState();
                        if ($state == 'export')
                            {
                             $crud->columns('firstName','lastName');
                            }
                        $output = $crud->render();
                        $this->_example_output($output);
}

In this case list view shows all table columns as expected.

Clicking on export button gives me a csv with all columns instead of just the two required.

Can't understand why.

 

Mirko


Dogtooth
  • profile picture
  • Member

Posted 31 January 2015 - 14:30 PM

Out of curiosity I took your test() and pasted it in my project. Works like it's supposed to, I can't recreate your error.


vgsangiuliano
  • profile picture
  • Member

Posted 03 February 2015 - 16:38 PM

HI,

thank you all for your help.

I can't have it working.

Did it again from scratch.

Copied CodeIgniter-2.2.1 and grocery-crud-1.5.0 to a new webserver folder.

Created a new DB and imported examples_database.sql

Changed database.php with my new DB, username and password.

Edited examples.php under controllers.

	public function employees_management()
	{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('employees');
			$crud->set_relation('officeCode','offices','city');
			$crud->display_as('officeCode','Office City');
			$crud->set_subject('Employee');

			$crud->required_fields('lastName');

			$crud->set_field_upload('file_url','assets/uploads/files');

//HERE BEGIN CHANGES WITH RESPECT TO SOURCE CODE
                     $state = $crud->getState();
                        if ($state == 'export')
                            {
                             $crud->columns('Email');
                            }
// HERE END CHANGES WITH RESPECT TO SOURCE CODE
		       $output = $crud->render();

			$this->_example_output($output);
	}

I made just few line of changes.

When I click on Export button on the top right of the page (close to Print button) I continue to have a csv with all table fields.

 

I tried to change code in

                     $state = $crud->getState();
                        if ($state == 'list')
                            {
                             $crud->columns('Email');
                            }

It shows just email field and when I click on export button I get a csv with just email column.

 

It seems it always exports what is shown on the screen.

 

Can figure it out....

 

Mirko


Amit Shah
  • profile picture
  • Member

Posted 04 February 2015 - 07:00 AM

well.. i have pm ed you a message.. look into it.. and lets work around accordingly for the solution