export based on column custom display

Questionsexport based on column custom display
Amir asked 11 years ago

I have a select statement like this:
SELECT t1.*, t2.*, t3.t3_field1, t3.t3_field5
FROM table1 t1
JOIN table2 t2 ON t1.userid = t2.userid
JOIN table3 t3 on t2.field_x = t3.field_4

both tables have over 60 columns each, but I'm only reporting on about half of them. I am using the grid for display and export purpose only (users can search and reduce the number of rows they see and then export.)

Further down the code I have :
$col = array();
$col["title"] = "Full Name";
$col["name"] = "t1_fullname";
$col["hidden"] = false;
$col["editable"] = false;
$cols[] = $col;

$col = array();
$col["title"] = "t3 data";
$col["name"] = "t3_field5 ";
$col["hidden"] = false;
$col["editable"] = false;
$cols[] = $col;

$col = array();
$col["title"] = "Middle Name";
$col["name"] = "t2_somedata";
$col["hidden"] = false;
$col["editable"] = false;
$cols[] = $col;

$col = array();
$col["title"] = "More t1 data";
$col["name"] = "t1_other";
$col["hidden"] = false;
$col["editable"] = false;
$cols[] = $col;

$col = array();
$col["title"] = "t3 data2";
$col["name"] = "t3_field1 ";
$col["hidden"] = false;
$col["editable"] = false;
$cols[] = $col;

There is a very big list of (about 60) columns here.

everything seems to work correct in displaying the grid and sorting the data.

When I export though, the fields are displayed in excel in the order of the SELECT statement and not in the order of the columns.
If I work with a small number of fields that's not an issue as I can manually enter the field names into the select statement. When working with a large number of fields, this becomes impossible. It can be done if the code never changes, but often we will get requests from the users to move fields around, introduce new fields etc.

If there a way to tell the export function to make use of only the columns in the $col array?


3 Answers
Abu Ghufran answered 11 years ago


Currently, it is not doable. it works with the sequence of sql query and table structure.
You can however formulate select_command, using the $cols array.

For e.g. iterate through the $cols[$i]["name"] and concat them to make sql.


Jorge Garcia answered 9 years ago

Is still not posible to export the grid result of my query based on visualization columns order?

Thanks in advance.

Best regards

Jorge Garcia

Abu Ghufran answered 9 years ago


Export with custom column order still not supported.
We added a feature to select particular column for display and export.


Code: Demo: http://phpgrid.org/demo/demos/export/export-selected.phps

Your Answer

13 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?