Is it possible to create Grid without With() variable? if yes then how?
Discussion posts and replies are publicly visible
Which type of Grid do you need? What's your use case?
Hi Mike, i want to create a paging grid.
Thanks - and what is your use case for needing to avoid with()?
You could re-evaluate your query for the datasubset in the saveInto of the gridField (and anywhere else that should update the data in the grid). It's a bit more cumbersome, but it will work.
Re-writing the example from the documentation this way would be:
=load( local!pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 5, sort: a!sortInfo(field: "label", ascending: true)), local!sampleData: { type!LabelValue(label: "John Smith"), type!LabelValue(label: "Michael Johnson"), type!LabelValue(label: "Mary Reed"), type!LabelValue(label: "Angela Cooper"), type!LabelValue(label: "Elizabeth Ward"), type!LabelValue(label: "Daniel Lewis"), type!LabelValue(label: "Paul Martin"), type!LabelValue(label: "Jessica Peterson"), type!LabelValue(label: "Mark Hall"), type!LabelValue(label: "Rebecca Wood") }, local!datasubset: todatasubset(local!sampleData, local!pagingInfo), local!dataForCurrentPage: local!datasubset.data, a!gridField( label: "Employees", instructions: local!pagingInfo, totalCount: local!datasubset.totalCount, columns: { a!gridTextColumn( label: "Name", field: "label", data: index(local!dataForCurrentPage, "label", null), alignment: "LEFT" ) }, value: local!pagingInfo, saveInto: {local!pagingInfo, a!save( local!datasubset, todatasubset(local!sampleData, local!pagingInfo) ), a!save( local!dataForCurrentPage, local!datasubset.data ) } ) )
It's especially possible if you don't need to page or sort. If your grid shows the same info in the same order the whole time a single user is using the form, you don't need to use the with for anything.
The whole purpose of the with() is simply to allow the grid to be restructured when you update the pagingInfo, either by changing which column you sort by, changing the direction you're sorting from ascending to decending or vice versa, or loading the next page of data. If your users aren't doing any of those things on your grid you don't need the with.
If you want users to be able to load completely new info onto the grid, you might just submit the form and loop users back into the same interface, using the PM to get the new data. This has the benefit of only reloading the data every time the user submits as opposed to every time the user interacts with anything at all. Or you could use the saveInto of the grid component itself to update the data as suggested by lucasj, thank you by the way. Your own individual needs should determine the best course of action.
This is along the lines of what I was thinking, but of course it 100% depends on the use case (versus, say, the use case posted below, which would require completely different implementation strategy). This is why I wanted OP to confirm their use case first, because otherwise all we're doing is throwing guesses into the wind.
Thanks Mike, I just wanted to show info without sorting and any user interactions.
thanks Lucas, yes, this is what i was looking for. It worked
Thanks David, yes i used saveInto of the grid component as i dint want users to interact with the grid.
If you won't be using sorting or any user interaction with the grid (including paging), i.e. display-only and all info on one page, you should probably follow the advice that posted below; however in this case, especially if you have no need of sorting or paging, I would strongly recommend you use an Editable grid as opposed to a Paging grid. Editable grids offer various benefits, including the ability to display rich text in a column.