Action with keyset pagination and dynamic filters

How to write an action with keyset pagination and filters like this: [{"field1", "value1"}, {"field2", "value2"}, ...] ?

You can filter an action that has keyset pagination like any other read action. You will first want to transform that list of tuples into a proper filter, which in your case may just mean atomizing the field name, i.e [{:field1, "value1"}, {:field2, "value2"}]. Would need more context to help any more than that.

Thanks, Zach.
Let’s suppose I have a proper filtter like this [{:field1, "value1"}, {:field2, "value2"}, ...]. How do I make it work?

    read :list do
      argument(:filters, :term)
      filter(expr(^arg(:filters)))
      pagination(keyset?: true, default_limit: 20, countable: true)
    end

Does that not work?

No. I’d like to make it work (or something like this). I’m building a dynamic table (spreadsheet) that has to be dynamically filtered by one or more columns, based on user input. I tried to write a regular function, but I couldn’t get it to return an %Ash.Page.Keyset structure. I tried to write several actions, but I couldn’t succeed on getting it to return the Keyset structure either. I don’t know how to achieve that. Could you help me?

Sorry, @zachdaniel. The problem was related to the calling function and not to the action definition. The action is working. Sorry about that.

1 Like