Sorting not working

Hi ,

In below code default sorting is not working on  UI interface. 

a!gridTextColumn(
label: "Served By",
field: "servedBy",
data:
a!applyComponents(
function: rule!getUserName(_),
array: ri!subset.data.servedBy
)

)

In this we are setting local.paginInfo in load and passing same on ein with() to this dataset subset. Then further this dataset i am passing to another rule where i am keeping grid section. 

After clicking on header column sorting should be work but its not working. Tried lot but not found feasible solution.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I sincerely hope you're not at a high enough version to support a!forEach and still using applyComponents.  A mighty strong kudos goes out to you for learning to use it, as I have learned it as well and fully understand how nigh impossible that is.  The problem is that the documentation is now so sparse that you're pretty much on your own if you ever have a bug in the applyComponents.  Also, a!forEach is faster, easier, literally faster as in it processes in fewer miliseconds, and more powerful, and more robust.  You can configure it to not crash and explode when it sees a null value.  a!forEach would be a great addition to this code.

    As to your current problem, I think your main difficulty is that your data is not in the form of a datasubset type.  You applyComponents a rule over the data of a datasubset, and it returns a bunch of data, but that data is not in the form of a subset itself.  What the datasubset provides you is a container that keeps both the data and the paging info in one place.  You've got paging info attached to your servedBy, whatever that is, but that's not what you're using for your grid.  Paging info is kind of worthless there.  If you were to attach the same to the output of your apply components, that should work.  Then the grid's paging info is right there with the data you ARE using to populate your grid.  When you change that paging info, you'll re-page the output of the applyComponents.

    Also, you probably want to do all the definition up in the local variables.  I wouldn't put super complex logic right there in the grid definition.  I'd just refer to complex logic I'd already done down there.

    with(

    local!dataForGrid: todatasubset(

    data: a!applyComponents(...your code...),

    pagingInfo: ri!subset.pagingInfo

    )

    ...several lines later

    a!gridTextColumn(

    label: "Served By", 
    field: "servedBy",

    data: local!dataForGrid,

    )

  • +1
    Certified Lead Developer
    in reply to Dave Lewis

    Reading this reply (which i generally agree with) makes me realize that we can't even guess as to why 's sorting isn't working without him posting more code (particularly, how the paginginfo and datasubset are defined in their local variables, and the saveIntos of the gridField).

    Also just as a general reminder, Community has a really neat feature for posting code in its own preformatted box which saves formatting, etc... i'm hoping if Sauravk posts a more verbose copy of the code he can use this feature Slight smile

  • Thanks Mike for your reply. But I have tried this but new issues are coming.

    Pasted here with or without save!value in code. I have used exact your code by replaced existing one.

    Used -save!value
      at function a!gridField: An error occurred while executing a save: Expression evaluation error at function a!gridSelection [line 155]: Could not find variable 'save!value'
     
      Used -local!gridSelection
      Expression evaluation error: The save target must be a load() variable, process variable, or node input (or a rule input passed one of those three), but instead was: [selected=, pagingInfo=[startIndex=1, batchSize=10, sort=[field=data.createdBy, ascending=true]]]

  • 0
    Certified Lead Developer
    in reply to sauravk

    Please post the entire form code again as it exists after you swapped in my saveInto code.  Also, can you please confirm what Appian version you're currently on?

  • I am sorry I had missed one tag a!save(). Now I have replaced this code again but now no paging is working on same page only 10 records are coming as batch size is 10 but its not even moving to next page also.

    saveInto: {
               a!save( local!gridSelection,
                /*if(*/
                  /*count(*/
                    /*local!gridSelection.selected*/
                  /*) > 1,*/
                  /*a!save(*/
                    /*local!gridSelection.selected,*/
                    /*local!gridSelection.selected[count(*/
                      /*local!gridSelection.selected*/
                    /*)]*/
                  /*),*/
                  /*{}*/
                /*),*/
                a!gridSelection(
          pagingInfo: local!gridSelection.pagingInfo,
          selected: if(
            count(local!gridSelection.selected) > 2, /* if user clicks "select all", keeps previous selection */
            local!gridSelection.selected,
            index(
              local!gridSelection.selected,
              count(local!gridSelection.selected), /* selects the latest-checked item; safely handles when the selection is un-checked */
              {}
            )
          )
        ))
               
              },

  • 0
    Certified Lead Developer
    in reply to sauravk

    It won't work like this - you need to use save!value as in my example above, as it holds the entire value gridSelection value being passed back to the saveInto variable.  The way you have it set up here, it will never update paging because you're just overwriting it with its own value for every save operation.  If save!value isn't working for some reason, we need to troubleshoot and figure out why, not just replace it with something that doesn't do the same thing.

    Also: I just realized you're declaring your local!gridSelection in the parent rule and referring to it in the child rule - this works by basic inheritance but I think it might not work when trying to saveInto local!gridSelection from the child.  You really should add a rule input for gridSelection in the child rule and pass in local!gridSelection to it from the parent, then in the child replace any references to local!gridSelection with ri!gridSelection.

  • I had tried both. But atleast with your code paging is working but sorting still have same issue.

     saveInto: {
                /*if(*/
                  /*count(*/
                    /*local!gridSelection.selected*/
                  /*) > 1,*/
                  /*a!save(*/
                    /*local!gridSelection.selected,*/
                    /*local!gridSelection.selected[count(*/
                      /*local!gridSelection.selected*/
                    /*)]*/
                  /*),*/
                  /*{}*/
                /*),*/
               a!save(
        local!gridSelection,
        a!gridSelection(
          pagingInfo: save!value.pagingInfo,
          selected: if(
            count(save!value.selected) > 2, /* if user clicks "select all", keeps previous selection */
            local!gridSelection.selected,
            index(
              save!value.selected,
              count(save!value.selected), /* selects the latest-checked item; safely handles when the selection is un-checked */
              {}
            )
          )
        )
      ),

  • Let me try by passing ri!gridSelection also. Lets check this option also.

  • 0
    Certified Lead Developer
    in reply to sauravk

    Please see the second half which I just added to my previous reply - basically I'm concerned with you trying to save into local!gridSelection when it's defined in the parent interface and not passed down via a Rule Input.

    For your reference here's a simple, one-interface pre-19.2 paging grid that I just wrote from scratch, and handles your use case perfectly as far as I can tell, including sorting on the one column I added as well as paging, plus preventing the user from selecting more than one item.

    load(
      local!gridselection: a!gridselection(
        pagingInfo: a!pagingInfo(1,10),
        selected: {}
      ),
      
      with(
        local!dataSubset: rule!MyQuery(
          pagingInfo: local!gridselection.pagingInfo
        ),
        a!gridField(
          label: "TEST",
          totalCount: local!dataSubset.totalCount,
          selection: true(),
          identifiers: local!dataSubset.data.Id,
          value: local!gridselection,
          saveInto: {
            a!save(
              local!gridselection,
              a!gridSelection(
                pagingInfo: save!value.pagingInfo,
                selected: if(
                  count(save!value.selected) > 2,
                  local!gridselection.selected,
                  index(
                    save!value.selected,
                    count(save!value.selected),
                    {}
                  )
                )
              )
            )
          },
          columns: {
            a!gridtextcolumn(
              data: local!dataSubset.data.Id,
              field: "Id"
            )
          }
        )
      )
    )

  • Sorry no impact after changing code with ri!gridSelection also.

  • Its ok Mike you have given a lot of solution but issue could be something else . But thanks for your time .

    Please have a look on this reply which I got on different thread for same issue, I don't know but I feel that could be the reason of this issue or by that we can solve this.

    https://community.appian.com/discussions/f/user-interface/17103/a-gridfield-sorting-issue)

Reply Children
No Data