Skip to main content
priyankaa0002
July 13, 2021
Solved

Sorting by date is not working on Read- only grid

  • July 13, 2021
  • 14 replies
  • 1 view

Hello Everyone,

I am using below pagingInfo , gridcolumn , and pagingSaveInto in my interface where Approval Date is of datetime type

local!pagingInfo: a!pagingInfo(

startIndex:1,

batchSize: -1,

sort: a!sortInfo(field: "APPORVAL_DATE")

gridColumn(

label: "Approved On",

sortField: "APPORVAL_DATE",

value: fv!row.APPORVAL_DATE

)

pagingSaveInto: local!pagingInfo

 If approval date is between 7/1/2021 and 7/12/2021 then 

Expected result to be sorted by Date ie. 7/12, 7/11, 7/10, 7/9, 7/8, 7/7 and so on but sorting is not applied to the grid and resulting data is random sequence like 7/11 7/12 7/1 7/2 and so on.

Thank you for suggestions in advance.

Best answer by selvakumark

Then I suspect the issue is in the datatype of that specific value. For example, in my sample code, I've just cast the DateTime value to a string. As a result, the sorting is not as expected.

a!localVariables(
  local!data: a!forEach(
    items: enumerate(5) + 1,
    expression: {
      id: fv!item,
      APPORVAL_DATE: tostring(now() - fv!item)
    }
  ),
  local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: - 1,
    sort: a!sortInfo(field: "APPORVAL_DATE")
  ),
  {
    a!gridField(
      label: "Read-only Grid",
      labelPosition: "ABOVE",
      data: local!data,
      columns: {
        a!gridColumn(
          label: "Date",
          sortField: "APPORVAL_DATE",
          value: fv!row.APPORVAL_DATE
        )
      },
      initialSorts: a!sortInfo(field: "APPORVAL_DATE", ascending: true()),
      validations: {},
      pagingSaveInto: local!pagingInfo
    )
  }
)

Can you try casting the API result to a proper datatype?

14 replies

selvakumark
Participating Frequently
July 13, 2021

Hi [mention:3514f00d0ed94e3bb86141b9fcae27e6:e9ed411860ed4f2ba0265705b8793d05],

Do you expect the data to be sorted on the interface load? If yes, then you might need to specify the initialSorts parameter of the read-only grid.

The sample code is below:

a!localVariables(
  local!data: a!forEach(
    items: enumerate(5) + 1,
    expression: { id: fv!item, APPORVAL_DATE: now() - fv!item }
  ),
  local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: - 1,
    sort: a!sortInfo(field: "APPORVAL_DATE")
  ),
  {
    a!gridField(
      label: "Read-only Grid",
      labelPosition: "ABOVE",
      data: local!data,
      columns: {
        a!gridColumn(
          label: "Date",
          sortField: "APPORVAL_DATE",
          value: fv!row.APPORVAL_DATE
        )
      },
      initialSorts: a!sortInfo(field: "APPORVAL_DATE", ascending: true()),
      validations: {},
      pagingSaveInto: local!pagingInfo
    )
  }
)

priyankaa0002
July 13, 2021

Hi Selvakumar,

I have tried to give initialSorts for sorting on interface load ans also given secondarySorts to keep sorting with user interaction. But resultant grid data is not sorted as expected.

selvakumark
Participating Frequently
July 13, 2021

What is your grid source? Whether it's a record type (or) data retrieved from other rules? Because in the example that I provided, it was working fine. Could you please let me know if I'm missing something?

mikes0011
Brainy
July 13, 2021

What is the type of APPORVAL_DATE within your CDT?  The behavior you describe sounds as if it's sorting these values as if they were plaintext.

The Expression Guru
davel001150
July 13, 2021

My theory as well, it looks like it's trying to alphabetize your dates rather than count them.  I don't know if an explicit cast inside your sort statement will help, but that's what I would try first.

mikes0011
Brainy
July 13, 2021

From further comments in the earlier thread it looks like the data is coming in (perhaps in plaintext) via an API call.  I'd guess that some transform could be done on the data prior to sorting, though that depends on a lot of factors and would grow pretty complicated pretty quickly.

The Expression Guru