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.
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.
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, 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;