Filtering a datagrid with alias [Helpful hint]

Talk about Filter (search) Settings

Moderator: alexandrleonenko

dynsight
Expert
Expert
Posts: 99
Joined: Mar 3rd, '11, 03:05

Filtering a datagrid with alias [Helpful hint]

Postby dynsight » Oct 17th, '11, 01:32

Here is the select statement for my table:

Code: Select all

  $sql="SELECT nr.id,
   nr.title,
   nr.category,
   nc.catName,
   nr.content,
    nr.image,
   nr.imageAlign,
   nr.isActive,
   nr.date
   
FROM newsresources nr INNER JOIN newscats nc ON nr.category = nc.id";


All works fine except when I try to filter:

Code: Select all

$catArray=array("1"=>"news","2"=>"resource","3"=>"both");

$filtering_fields= array(
"Search"=>array(
"type"=>"textbox",
"table"=>"newsresources",
"field"=>"title",
"show_operator"=>"true",
"comparison_type"=>"string|numeric"),

"Category"=>array(
"type"=>"dropdownlist",
"table"=>"newsresources",
"field"=>"category",
"comparison_type"=>"numeric",
"source"=>$catArray
),


);
   
$dgrid->SetFieldsFiltering($filtering_fields);   


It never yields any results always returns null.

The solution....
"table"=>"newsresources",
should be
"table"=>"nr"

administrator
Site Admin
Site Admin
Posts: 6010
Joined: Jan 7th, '09, 23:18
Contact:

Re: Filtering a datagrid with alias [Helpful hint]

Postby administrator » Oct 17th, '11, 08:49

We recommend do use non-documented attribute for filtering fields:
"table_alias" => ""
that defines table alias for filtering fields to prevent name overlapping


Return to “Settings: Filtering (search) / Autocomplete”