Sorting on displayed data rather than ID

QuestionsSorting on displayed data rather than ID
Steve asked 9 years ago

Hi,

I have a grid set up with a Join to another table. The join is shown in the grid as a select column and is working really well. The only problem is when I click on the column heading to sort. The sort is on the primary ID, rather than the displayed text.

Is there anyway I can change this please?

Cheers

Steve.

7 Answers
Abu Ghufran answered 9 years ago

You can specify the actual column name (other than id) like following:
$col["dbname"] = "table.field";

This will be used when you sort and search on grid.

Steve answered 9 years ago

Hi Abu,

Thank you for the reply. I have added this and it still appears to sort by ID instead of the text. Here is my code for the column:-

$col = array();
$col["title"] = "Brand"; // caption of column, can use HTML tags too
$col["name"] = "brand_id"; // grid column name, same as db field or alias from sql
$col["dbname"] = "tbl_sm_brand.brand_name";
$col["fixed"] = false;
$col["width"] = ""; // width on grid
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
# on change, update other dropdown
$str = $g->get_dropdown_values("select distinct brand_id as k, brand_name as v from tbl_sm_brand");
$col["editoptions"] = array(
"value"=>$str,
"onchange" => array( "" )
);
$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$col["viewable"] = true;
$col["isnull"] = true;
$col["autoid"] = false;
$col["hidden"] = false;
$col["align"] = "left";
$col["sortable"] = true;
$cols[] = $col;

I would like it to sort using the brand_name rather than brand_id when I click on the column title.

Steve.

Abu Ghufran answered 9 years ago

I've emailed you updated build, and it should work after that.

Steve answered 9 years ago

Thank you for the help Abu. All sorted now.

Steve.

Abu Ghufran answered 9 years ago

Update sent!

Newman Viloria answered 8 years ago

Abu, hi. Same problem here.

Here you have column code. Cheers.

$col = array();
$col["title"] = $lang['AREAS'];
$col["name"] = "area_id";
$col["dbname"] = "area.area";
$col["formatter"] = "select";
$col["width"] = "200"; // width on grid
$col["search"] = true;
$col["editable"] = true;
$str = $area_grid->get_dropdown_values("select distinct id as k, area as v from area");
$col["edittype"] = "select";
$col["editoptions"] = array("value" => $str, "separator" => ":", "delimiter" => ";");
$col["searchoptions"] = array("value" => $str, "separator" => ":", "delimiter" => ";");
$col["sortable"] = true;
$col["sorttype"] = text;
$cols[] = $col;

Newman Viloria answered 8 years ago

Thank you Abu.

Solved with the update.

Cheers.

Your Answer

17 + 17 =

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?