-2

I have a dropdown that have 3 values (Status Values): All, Active, Inactive and a Table with results.

The dropdown will filter the table results by the status, this status depends on a field that is from Date value.

  • Active: End_date is null. Returns the results that do not have a end_date

  • Inactive: end_sate is not null. Returns the results that have a end_date

  • All: will not query by nothing. Returns all results

Pavel Shkleinik
  • 6,298
  • 2
  • 24
  • 36
JingleBells
  • 47
  • 1
  • 11

1 Answers1

0

First things first you need to create a parameter in your query script datasource: Query script parameter

Once you have the parameter, you can bind it to dropdown's value and add the following code to the onValueChange event

app.datasources.MyTableDatasource.load();

Your query script code will look similar to this:

var status = query.parameters.Status;

switch(status) {
  case 'Active':
    query.filters.end_date._equals = null;
  break;

  case 'Inactive':
    query.filters.end_date._notEquals = null;
}

// we keep original query to preserve its paging and sorting settings
// and we do not set any additional filters in case selected status
// is not Active or Inactive
return query.run();
Pavel Shkleinik
  • 6,298
  • 2
  • 24
  • 36
  • Hello @Pavel Shkleinik Thanks for the response. after all changes still got an error: Executing query for datasource DRIVERS_LIST: (Error) : Cannot set property "_equals" of undefined to "null". at datasources.DRIVERS_LIST.script:16 script: var status = query.parameters.Status; switch(status) { case 'Active': query.filters.end_date._equals = null; break; case 'Inactive': query.filters.end_date._notEquals = null; break; case 'All': query.clearFilters(); break; default: query.filters.end_date._equals = null; } return query.run(); – JingleBells Mar 22 '18 at 19:48
  • Most likely you made a typo or didn't update field name here: `query.filters.._equals = null;` – Pavel Shkleinik Mar 22 '18 at 19:52
  • it worked out. Newbie error in here. Thank you so much – JingleBells Mar 22 '18 at 19:54
  • Welcome! Don't forget to accept the answer to help other developers like you. – Pavel Shkleinik Mar 22 '18 at 19:59