KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Reorder Exported Columns #539

Open Alex Chartier opened this topic on on Nov 30, 2018 - 8 comments

Alex Chartier commented on Nov 30, 2018

My browser outputs columns Attendee, Guest(s) and Volunteer to Help. The exported excel spreadsheet has the column order Attendee, Volunteer to Help and Guest(s).

I added a function for reordering but when I look at the existing $meta it is already in the correct order, the same order as the browser output. Did I miss something?

Alex Chartier commented on Nov 30, 2018

Here is the meta that I am passing back in the meta function: Array ( [columns] => Array ( [Attendee] => Array ( [type] => string ) [Guest(s)] => Array ( [type] => string ) [Meal Choice] => Array ( [type] => string ) [Extras] => Array ( [type] => string ) ) )

and I have attached a screenshot of the excel spreadsheet.

Alex Chartier commented on Dec 6, 2018

Any Ideas?

Andrew Borell commented on Dec 8, 2018

Your initial detail says your browser presents: "Attendee","Guest(s)","Volunteer to Help".

Your metadata shows "Attendee","Guest(s)","Meal Choice","Extras"

Your screenshot shows: "Attendee","Meal Choice","Extras","Guest(s)"

In the initial detail I presume you are referencing the wrong dataStore. Your metadata does not match the spreadsheet, but its not clear what order you wish to see it. The order on screen is dictated in table format purely by the top-down order you list the columns when you create the columns array for the table object.

DataTables::create(array(
"dataSource"=>$report->dataStore($report->dataStore("ds_name_here"))
	,"columns"=>array(
		"attendee"=>array(
			"label"=>"Attendee",
			"type"=>"string",
			)
		,"guests"=>array(
			"label"=>"Guest(s)",
			"type"=>"string",
			)	
		,"meal_choice"=>array(
			"label"=>"Meal Choice",
			"type"=>"string",
			)
		,"extras"=>array(
			"label"=>"Extras",
			"type"=>"string",
			)
		)
	,"options"=>array(
		"paging"=>true,
		"searching"=>true,
		)
));

If you are saying the columns are out of order when exporting a spreadsheet, then list them in your select statement in the order which you wish to export them, or map the array as described in this thread: https://www.koolreport.com/forum/topics/329

Alex Chartier commented on Dec 9, 2018

I haven't forgotten about this Andrew, just busy putting the final touches on the online report process. I will get back to this once that part is done.

Andrew Borell commented on Dec 9, 2018

I have found enough resources in the 500 or so threads in this forum to answer all of my questions where documentation lacked clarity. If you are sharp with PHP and Javascript you will get past any problem. Best of luck!

Alex Chartier commented on Dec 10, 2018

I am pretty good with PHP and getting better with JS so with help from the forum should be good to go. Thanks again.

KoolReport commented on Dec 10, 2018

Really sorry for our late answer, we will improve the documentation for better clarity. Forum topics is good source for real case usage. You can find similar issue most of the time. We also use forum topics to search for old cases to support as well.

Alex Chartier commented on Dec 18, 2018

OK, so getting back to this. I still find the exported columns are in a different order than what I set them to . Below is a screen grab of the report:

Here is a screen grab of the excel spreadsheet:

Here is the column data from the Table::Create:

array ( 
	'Attendee' => array('label' => 'Attendee', 'cssStyle' => array('td' => 'padding-top:4px;padding-bottom:4px;',), ), 
	'Guest(s)' => array('label' => 'Guest(s)', 'cssStyle' => array('td' => 'padding-top:4px;padding-bottom:4px;',), ), 
	'Meal Choice' => array('label' => 'Meal Choice', 'cssStyle' => array('td' => 'padding-top:4px;padding-bottom:4px;',), ), 
	'Extras' => array('label' => 'Extras', 'cssStyle' => array('td' => 'padding-top:4px;padding-bottom:4px;',), ), 
	'Column 1' => array('label' => 'Column 1', 'cssStyle' => array('td' => 'padding-top:4px;padding-bottom:4px;',), ), 
	'Column 2' => array('label' => 'Column 2', 'cssStyle' => array('td' => 'padding-top:4px;padding-bottom:4px;',), ), 
)

and here is the meta data from the meta pipe:

"columns" => Array ( 
	"Attendee" => Array ( "type" => string ),
	"Guest(s)" => Array ( "type" => string ),
	"Meal Choice" => Array ( "type" => string ),
	"Extras" => Array ( "type" => string ),
	"Column 1" => Array ( "type" => string ),
	"Column 2" => Array ( "type" => string ) 
	)
);

and finally the code use to generate the meta:

	$source->pipe(new \koolreport\processes\Map(array(
		'{meta}' => function($meta) {
			$newMeta = ['columns' => []];
			/* First are the Attendee & guest fields */
			$newMeta['columns']['Attendee'] = $meta['columns']['Attendee'];
			if (array_key_exists('Guest(s)', $meta['columns'])) {
				$newMeta['columns']['Guest(s)'] = $meta['columns']['Guest(s)'];
			}
			/*  Now the template fields */
			foreach($this->selectedOptions as $selectedOption) {
				$title = $this->selectedOptionDetails[$selectedOption]['title'];
				if (array_key_exists($title, $meta['columns'])) {
					$newMeta['columns'][$title] = $meta['columns'][$title];
				}
			}
			/* And now the extra fields */
			foreach($this->additionalColumns as $additionalColumn) {
				if (array_key_exists($additionalColumn, $meta['columns'])) {
					$newMeta['columns'][$additionalColumn] = $meta['columns'][$additionalColumn];
				}
			}

			return $newMeta;
		},
	)));

Somethings wrong but I know not what. Looking for help, thanks.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None