Author Topic: Modify range values  (Read 2218 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Modify range values
« on: April 13, 2021, 12:35:57 pm »
Would it be possible to modify values used in range condition? Fetching values remotely from DB.

Have values like 'value a, value b' but would like them to be splitted by comma (,) in the filter menu for range condition, ex:

value a, value b becomes:

- value a
- value b

« Last Edit: April 13, 2021, 12:54:27 pm by queensgambit9 »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Modify range values
« Reply #1 on: April 13, 2021, 05:41:09 pm »
Is there a way to do it in callback in the column definition or is the prefered way to do it in the response from ajax call before values are assigned as options?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Modify range values
« Reply #2 on: April 14, 2021, 11:38:16 am »
Quote
Would it be possible to modify values used in range condition?

options displayed in the filter dropdown for range condition can be customized by declaring column.filter.options array or a callback returning an array.
Reference: https://paramquery.com/pro/api#option-column-filter

Also please check "(Shipped - Order) Days" in this example: https://paramquery.com/pro/demos/filter_custom

Quote
Fetching values remotely from DB.

you mean field values displayed in the grid, right?
options displayed in the filter dropdown can be built synchronously ( without separate Ajax request ) from the values displayed in the grid itself ( in case of local or no paging ) by using getDataCascade method.

http://paramquery.com/pro/api#method-getDataCascade
« Last Edit: April 14, 2021, 12:01:19 pm by paramvir »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Modify range values
« Reply #3 on: April 14, 2021, 12:24:44 pm »
I fetch filter values to populate range condition from DB (select distinct) to get all values and not only them available in grid. Tried using options but can't get it to work.
Seems to work when modifying the response from ajax call to get header options before assigning them.

Instead of equal condition in Range, I would like to use contain condition. Do I need custom override for this? Is there a sample available in that case?

Thanks.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Modify range values
« Reply #4 on: April 14, 2021, 12:42:17 pm »
Kindly confirm whether it's local or remote filtering.

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Modify range values
« Reply #5 on: April 14, 2021, 12:58:56 pm »
Remote.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Modify range values
« Reply #6 on: April 14, 2021, 05:10:36 pm »
Quote
Instead of equal condition in Range, I would like to use contain condition. Do I need custom override for this? Is there a sample available in that case?

FilterHelper::_range method can be customized as below:

Code: [Select]
public static function _range($dataIndx, &$fcrule, &$param, $value){
    $arrValue = $value;
    $fcRange = array();
    foreach ($value as $val){
        if ($val == ""){
            //continue;
            FilterHelper::_empty($dataIndx, $fcRange);
        }
        else{
            //$fcRange[] = $dataIndx."= ?";
            $fcrule[] = $dataIndx . " like CONCAT('%', ?, '%')";
            $param[] = $val;
        }
    }
    $fcrule[] = (sizeof($fcRange)>0)? "(". join(" OR ", $fcRange) .")": "";
}