filter initially causes grid to contain no data

Talk about Filter (search) Settings

Moderator: alexandrleonenko

Emmanuel71
Junior
Junior
Posts: 11
Joined: Apr 19th, '13, 17:56

filter initially causes grid to contain no data

Postby Emmanuel71 » Aug 10th, '16, 14:57

Hi,

I'm starting a new topic for a previously posted filtering problem. Just to be able to clearly state what the problem is at present, without the confusioning previous posts. Hope that's ok. We are using the datagrid version 8.1.8. The project was originally created with the datagrid wizard and then edited afterwards. My filtering section is declared as follows:

## +---------------------------------------------------------------------------+
## | 5. Filter Settings: |
## +---------------------------------------------------------------------------+
## *** set filtering option: true or false(default)
$filtering_option = true;
$show_search_type = true;
$dgrid->AllowFiltering($filtering_option, $show_search_type);

$fill_from_array = array('0'=>'Nee', '1'=>'Ja');
$filtering_fields = array(
'onderwerp'=>array('type'=>'textbox','table'=>'st_steuntaken','table_alias' => 'st','field'=>'naam','field_view'=>'','default_operator'=>'%like%','default'=>'ee','case_sensitive'=>'false','comparison_type'=>'string',),
'Af'=>array('type'=>'enum', 'table'=>'st_steuntaken','table_alias' => 'st','field'=>'volledigafgewerkt','filter_condition'=>'', 'show_operator'=>'false', 'default_operator'=>'=', 'case_sensitive'=>'false', 'comparison_type'=>'numeric', 'width'=>'', 'on_js_event'=>'', 'default'=>'', 'source'=>$fill_from_array, 'view_type'=>'radiobutton', 'field_view'=>'volledigafgewerkt', 'order_by_field'=>'', 'order_type'=>'ASC', 'condition'=>'', 'show_count'=>false, 'multiple'=>'false', 'multiple_size'=>'4'),
);
$dgrid->SetFieldsFiltering($filtering_fields);
$dgrid->AllowDefaultFiltering(true);


My problem is: initially there is no data displayed and the default filter value for 'onderwerp' (that means subject in dutch) is all data that contains the string 'ee' (just as an example). When I click 'search' in this situation, the data is correctly displayed. Do you have an idea what the problem could be? Why isn't the data correctly displayed immediately? Sorry if I'm missing something simple...

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

Re: filter initially causes grid to contain no data

Postby administrator » Aug 11th, '16, 13:26

Try $dgrid->AllowDefaultFiltering(false);

Emmanuel71
Junior
Junior
Posts: 11
Joined: Apr 19th, '13, 17:56

Re: filter initially causes grid to contain no data

Postby Emmanuel71 » Aug 11th, '16, 14:00

That works but gives me all the data on page load. I want to set a filter at page load. Problem is that when I set a filter, no records are displayed at page load until the search button is clicked. Could I somehow use js to hit that button programmatically only the first time the page is loaded? Or is there a cleaner solution? Thx for any suggestions.

Emmanuel71
Junior
Junior
Posts: 11
Joined: Apr 19th, '13, 17:56

Re: filter initially causes grid to contain no data

Postby Emmanuel71 » Sep 7th, '16, 12:26

Hello,

I found the solution to the problem. After turning debug mode on I saw that there was an issue with the sql statement. The statement is a bit complex with a few subselects. This caused the grid component not to add the where clause for the filter correctly at the end of the sql-statement. I solved it by adding 'where 1' (= always true) at the end of the sql-statement.

A second problem consisted in the fact that I had to use the table alias instead of the table name in the 'table'=> definition of the filter field. I don't understand why, but that made it work.

I should have turned debug mode on sooner instead of wasting your time... sorry :oops:


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