How can I have two different Paging Grids on the same interface?

Hi All,

I'm less than two weeks of working with SAIL and I have a paging grid on my interface (which is working as I want to).  Very happy about that, thanks mostly to the support I have received from this forum.  However, I need to include a different Paging Grid using a different data source into the same interface.  In the example code I used for the first Paging Grid (see SAIL code below), I defined the query for the grid data source in the with() function of the interface.  What I am now trying to find out is if I can have a second query defined in my with() so I can use for my second grid, and where I might place it (getting errors that I cannot us multiple datasubsets).  If not, how might I created a second Paging Grid and also define a query from a CDT as the data source for the second Paging Grid?

Thanks.

---

=load(
  local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: 20
   ),
  with(
    local!datasubset: a!queryEntity(
      entity: cons!CSHV_LINE_ITEM_CDT,
      query: a!query(
      selection: a!querySelection(columns: {
          a!queryColumn(field: "itemName"),
          a!queryColumn(field: "amount"),
          a!queryColumn(field: "qty"),
          a!queryColumn(field: "total"),
        }), 
      filter: a!queryFilter(
     field: "cashAdvnaceId.id",
     operator: "=",
     value: ri!CashAdvanceData.id
      ),
      pagingInfo: local!pagingInfo
      )
    ),
   
    ...

    ...

    ...

 


       

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    Hi, You can definitely have a second query defined in the with(), you would just need to put it below the definition for the local!datasubset variable, and give it a different name.
  • I'd also add that you'll need another pagingInfo variable, which should go in the load().
  • +1
    Certified Lead Developer
    in reply to seanw583
    Good point. Essentially, your code should look like this (I modified some variable names to make it clearer):

    =load(
    local!firstPagingInfo: a!pagingInfo(...),
    local!secondPagingInfo: a!pagingInfo(...),
    with(
    local!firstDatasubset: a!queryEntity(
    entity: ... ,
    query: a!query(
    ...
    pagingInfo: local!firstPagingInfo
    )
    ),
    local!secondDatasubset: a!queryEntity(
    entity: ... ,
    query: a!query(
    ...
    pagingInfo: local!secondPagingInfo
    )
    ),

    ...

    ...

    ...
  • As the other users have said, the main takeaway here is that "local!pagingInfo" and "local!dataSubset" are just variable names and could be renamed to anything else.

    One practice I find helpful is to name my paging infos according to the data type they will be paging. So if I have a form with one grid of documents and one grid of contracts, for example, I will name my variables local!documentPagingInfo and local!contractPagingInfo, and name my datasubsets similarly.

  • +1
    Certified Lead Developer

    I would recommend having your queries in load() local variables rather than inside with(). When a component inside the with() is interacted with, all of the variables are recalculated, so both of your queries would be re-queried anytime you sort or page. Here is another way to structure your SAIL code to be better performant.

    load(
    local!firstQuery,
    local!secondQuery,
    local!firstpagingInfo,
    local!secondPagingInfo,

    with(
    local!firstDataSubset: todatasubset(local!firstQuery, local!firstPagingInfo),
    local!secondDataSubset: todatasubset(local!secondQuery, local!SecondPagingInfo),
    {
    /*First Paging Grid*/
    a!gridField()

    /*Second Paging Grid*/
    a!gridField()

    }
    )
    )

  • If you want to be more careful about performance, you can page the queries themselves instead of moving paging into the with() block. Something like  the following:

    =load(
      local!firstPagingInfo,
      local!secondPagingInfo,
      local!firstQuery: rule!query(pagingInfo: local!firstPagingInfo),
      local!secondQuery: rule!query(pagingInfo: local!secondPagingInfo),
      
      {
        /* first grid */
        a!gridField(
          value: local!firstPagingInfo,
          saveInto: {
            local!firstPagingInfo,
            a!save(
              local!firstQuery,
              rule!query(pagingInfo: local!firstPagingInfo)
            )
          }
        ),
        /* second grid */
        a!gridField(
          value: local!secondPagingInfo,
          saveInto: {
            local!secondPagingInfo,
            a!save(
              local!secondQuery,
              rule!query(pagingInfo: local!secondPagingInfo)
            )
          }
        )
      }
    )

  • Thanks all for your kind answers and code samples. I have set it up for two grids on a page thanks to you. Enjoy the rest of your day(s).
  • Hi friends,

    Is it possible to append two datasubsets and show it in the single grid which is total count differen?

    Business Case: Initially the application was task based , now client wants it to be record based.
    I have added the related actions.
    Now I want to show all the active tasks from old report ( which is from task based ), new tasks from the related actions .
    I am unable to do this because of the total count issue.

    In my old report I have 3 tasks and new report I have 6 tasks.
    And if suppose I give the batchsize=3 .

    I am getting the below error
    A grid component [label=“”] has an invalid value for “value” and “totalCount”. “startIndex” must not be greater than “totalCount”, but “startIndex” was 4 and “totalCount” was 3.



    Here is code

    load(local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize:3
    ),


    with(

    /* Fetching the datasubsets here */

    local!tempData:append(index(local!datasubsetOldTaskList,"data"),
    index(local!datasubsetNewTaskList,"data")
    ),
    local!tempDataSubset: todatasubset(
    local!tempData, local!pagingInfo
    ))
  • Hi,

    It is possible to combine datasubsets, such as the following:

    =load(
      local!ds1: rule!query1(),
      local!ds2: rule!query2(),
      local!pagingInfo: topaginginfo(1,10),
      with(
        local!datasubset: todatasubset(
           {
             local!ds1.data,
             local!ds2.data
           },
           local!pagingInfo
        ),
        a!gridField(
          value: local!pagingInfo,
          saveInto: local!pagingInfo,
          totalCount: local!datasubset.totalCount,
          columns: {...}
        )
      )
    )

    However, this requires querying all data up front, so whenever possible you should look into using a view to combine the datasets you are working with rather than doing it like this on-form.

  • As long as all variables used in the grids are specified for the grid with the desired data, you can have many grids on one interface. The more description your local variables are and expression rules with the queries, the easier it will be for someone else to understand your code later.