2

I have created one datasource which contains only the rows that fulfil one condition. I want to create some filters in this table... but is not working.

This is the datasource: enter image description here

For example, I have a text area which filters by the field "Title". Only should appears the row 5 , but the numer 6 it's still here...

enter image description here

This is the event handler code:

enter image description here

Important: in the beginning, I used this filters and they worked properly. They stopped working when i created the filter in the datasource (The one of the first image)

jbra95
  • 881
  • 2
  • 11
  • 30
  • The info you are providing is not enough. What is the event handler code that performs the filter? – Morfinismo Jul 26 '18 at 15:55
  • 1
    It looks like your datasource query script is set up incorrectly. Why are you referencing a different model in model datasource query script? If your point is to query all approved data with an additional filter on the Status, then you need to rewrite your query script. Also, you are returning a set of defined records since you are pushing approved records to your own record collection and then you are setting a page filter on the datasource, however your datasource returned a set of records that now needs to be filtered with a parameter vs a filter. – Markus Malessa Jul 26 '18 at 15:58
  • Still not clear what is happening. What is CP0794_data vs CP0794_approved_data? Are both of these datasources based on the same model? If so, what is your field that determines 'approved' vs something else? – Markus Malessa Jul 26 '18 at 16:05
  • @MarkusMalessa i have one datasource which contains all the data (CP0794_data) and another which contains only the approved requests (CP0794_approved_data)... i don't really now if it's a good practice – jbra95 Jul 27 '18 at 07:30
  • @JuanBravoRoig Did you end up figuring this out and stick with the simple query as you had indicated? Having the two separate datasources is definitely the way to go, however in your 'approved' datasource you should use just 'query' instead of app.models, since your datasource already points to that model. – Markus Malessa Jul 27 '18 at 13:42

1 Answers1

2

The filter that you are setting via the binding is getting lost when you perform your query script. Essentially, you are creating a query via the binding, then your script is creating a new query that doesn't have the filters you set previously.

Server Script - queryRecords(query: Query)

You'll notice that your query script has access to a parameter query that you can use instead of calling newQuery(). This will have the filter you set via your binding. Additionally, query.run() returns a list of records, so there's no need to iterate over them. Here is all the code you need in your query script:

query.filters.Status._in = ["Published"];
return query.run();