Skip to main content
fernandob9308
August 26, 2024
Question

Problem when applying a filter in a grid field displaying related data

  • August 26, 2024
  • 7 replies
  • 0 views

Hello,

I hope you can help me.

I have a gried Field with a record Type as the data source (record A), which at the same time is based on a SQL table. Every row has a unique value of its primary key (request_id).

Some of the columns of the grid are displaying values which are not from the main source record, but from another record with a one-to-many relationship.
This second record (record B) is also based on a SQL table.  The relationship between them is through request_id. Because of this, I have included record B within the "relatedRecordData" parameter of the "a!gridField". I have stablished as well a limit of 1, and a descending sort field based on the date. This way, for every a_id, I only display the value of the latest row in record B (even if there are more rows with different values).This is working completely find.

My problem comes when I try to add filters within "a!recordData" > "filters" .

The moment I add a filter that affects a field which is from record B, it also shows matches with values from rows that are not the last ones (the ones I am displaying).

For example; I have a column called "status" with different values such as "Started", "Completed" or"Canceled". If I select "Completed" in my multiple dropdown field, it displays rows which visible status is different to "Started", because in the record B, some of the rows for the same request_id have that particular status. This is wrong as I just want the filter to apply to the latest row of record B. 


If the data from the record B table looks like this:

request_id status created_date
1 completed today
1 started 1 day ago
2 canceled today
2 completed 1 days ago
2 started 2 days ago
3 started today

For each request_id, the grid displays just 1 (the one with the most recent date):

request_id status created_date
1 completed today
2 canceled today
3 started today

but, if i apply the filter status= completed, it displays :

request_id status created_date
1 completed today
2 canceled today

This is because reques_id also has status = "completed" in ones of its rows of the the record B table, but this is not what I want. It should only filter those that have status = "completed" in the very last row;

request_id status created_date
1 completed today

I have to add that I have also try to add the filters in the "relatedRecordData" section, but it also did not fix the problem.

What am I missing? It cannot be that an out of the box function as the grid Field with records as a source, and the filters of it are not working as intended...

Thanks for any help. 

7 replies

konduruc733182
August 27, 2024

Hello [mention:2cf025bfa9b448ccb2aea669fd772f7c:e9ed411860ed4f2ba0265705b8793d05] 

Not sure if I clearly got your requirement, but from what I understood you can simply use a if() condition to evaluate whether the relatedRecordData or the limit applies based on a null check for the status selected. But this will not work if the filters are User filters. This would be doable only if you have a custom filter created using dropdown outside the grid.

fernandob9308
August 27, 2024

Hello [mention:2df2892a4df7486f9775b4d2f0e405fd:e9ed411860ed4f2ba0265705b8793d05] ,

Thanks for your answer! 
Yes, the filters are not user filters, but filters within a!griedFiled > data > a!recordDara > filters and the values are influenced by multiple dropdows I have outside the grid. 

To be honest, I do not really understand what exactly is that I should evaluate or where exactly... Could you be a bit more specific? I can also try to rephrase something in case I was not clear enough with the problem...

Thanks again

konduruc733182
August 27, 2024

In the recordData, use if() condition for your relatedRecordData filters and the limit. 

a!recordData(
  relatedRecordData: a!relatedRecordData(
    relationship: "your record relationship",
    filters: if(
      a!isNullOrEmpty(ri!dropdownValue),
      {"apply query filter"},
      {}
    ),
    limit: if(
      a!isNullOrEmpty(ri!dropdownValue),
      {"apply limit"},
      {}
    )
  )
)