Disable sorting on one column only in a paging grid

I am currently working on a paging Grid. I want to achieve below functionality . Any help is appreciated .

-> I have around 10 columns . I just want to disable sorting on only one column and retain sorting on all other columns. Is there a way to achieve this . If Yes please share.

OriginalPostID-216660

OriginalPostID-216660

  Discussion posts and replies are publicly visible

  • Hi roopesh,

    In paging grid basically we will use field property to achieve sorting. this field property will be available in a!gridTextField() and a!gridImageField().
    Please refer the following links for more information.
    forum.appian.com/.../SAIL_Components.html
    forum.appian.com/.../SAIL_Components.html
  • @roopeshr Hope you are asking the question in the context of SAIL Forms. I believe providing a value (or a null value) to 'field' attribute that doesn't resolve to a valid field (as mentioned in the below example) name in the label-value/CDT array that goes to the paging grid should help you. If you do so, though you are able to click on the column, you won't be able to sort as the field is invalid.

    Example:
    a!gridTextColumn(
    field:""
    )
  • @rajashekarp,@sikhivahans,Many Thanks for your inputs, Can we block the sort for one single column , As per my understanding what you have mentioned in your post is right and we are facing that issue, but we are curious to know is there a way to stop for single column sort,
  • @harshav May I please know what is "block" as per you? As per my knowledge, if you want to provide a column with sorting capability, feed the 'field' attribute of a!gridTextColumn() with a value which is present in the CDT array or label-value pairs as a field and then sorting works.

    If you aren't interested in the sorting for a given column (or field), feed the 'field' attribute of a!gridTextColumn() with a invalid(that doesn't match a field in CDT)/null value and then sorting stops working for the corresponding column.
  • @sikhivahans I agree that it sort is not taking place when we pass fied: "" but it throws an error stating " Cannot sort by a blank field." and if we give some wrong column name in the filed : column (field: fieldName )then it throws "The field [fieldName does not exist." . so we are basically unable to remove sorting from one column.
  • 0
    Certified Lead Developer
    just remove the field attribute from your gridTextColumn() definition
  • 0
    Certified Senior Developer
    You should give the column you don't want to sort by the field: name of the default sort. I don't think you can disable being able to click and sort by a column, but you can change what the sort criteria that column uses are.
  • 0
    Certified Lead Developer
    If you don't provide the field attribute to gridTextColumn() it will nullify the sort attribute of your pagingInfo and effectively reset your datasubset to the default of the query. It sounds like you want to retain whatever is the current sort value when this happens.

    You can use something like the following on the saveInto of the gridField() to 1st capture the current sort value and then test to see if the column the user clicked on contains the field attribute, if not just reuse the previous sort value rather than the new one:

    value: local!pagingInfo,
    saveInto: {
    a!save(
    local!sortInfo,
    local!pagingInfo.sort
    ),
    a!save(
    local!pagingInfo.startIndex,
    save!value.startIndex
    ),
    a!save(
    local!pagingInfo.batchSize,
    save!value.batchSize
    ),
    a!save(
    local!pagingInfo.sort,
    if(
    rule!APN_isBlank(
    save!value.sort.field
    ),
    local!sortInfo,
    save!value.sort
    )
    )
    }
  • @roopeshr/harshav Hi, so I guess I am back with a solution. It might seem crazy to you but please do take a look at the code snippet attached here and try to improvise it as I have written it quite quickly. I have tested it and it worked like a charm for me.

    In short, I guess we can eliminate the error by handling the pagingInfo variable when there is a blank value or invalid value provided for the field which can be either intentional or by mistake.

    Below is the code at a high level and let's see what the community opines:
    a!save(
    local!pagingInfo,
    a!pagingInfo(
    startIndex: if(isnull(save!value.sort),local!pagingInfo.startIndex,if(length(save!value.sort.field)<=0,local!pagingInfo.startIndex,save!value.startIndex)),
    batchSize: if(isnull(save!value.sort),local!pagingInfo.batchSize,if(length(save!value.sort.field)<=0,local!pagingInfo.batchSize,save!value.batchSize)),
    sort: a!sortInfo(
    \ tfield: if(isnull(save!value.sort),local!pagingInfo.sort.field,if(length(save!value.sort.field)<=0,local!pagingInfo.sort.field,save!value.sort.field)),
    \ tascending: if(isnull(save!value.sort),local!pagingInfo.sort.field,if(length(save!value.sort.field)<=0,local!pagingInfo.sort.ascending,save!value.sort.ascending))
    \ t)
    )
    )
  • 0
    Certified Lead Developer
    @sikhi same result with very different looking code... that's Appian for you :-)