FlexGrid sort binding

Posted by: arodko on 8 August 2017, 10:40 am EST

  • Posted 8 August 2017, 10:40 am EST

    For some columns in my FlexGrid I wanted to change the sort binding so that the columns are sorted on a value which is different from what is displayed. What would be the best way to accomplish this?
  • Replied 8 August 2017, 10:40 am EST

    Can you be a little more specific about what you're trying to accomplish? I guess my main question is what is the other value that you want to be able to sort on (for example a hidden column, datamap)? I think a use case would be helpful too just to clarify the relationship between the displayed value and the value you want to sort on.
  • Replied 8 August 2017, 10:40 am EST

    I have some columns which are strings of dates. While one value could be "4/4/16", another value could be "4/4/16,4/5/16", so sorting on this won't work correctly. What I did was create another property which converted the string to a date by taking the first date in the string, and I'd like to sort on this date while displaying the string. I customized the sort under the sortingColumn delegate, and changed the property of XuniSortDescription from the column's binding to a different property of the column, and while this worked, there's a slight issue in that the sort indicator does not display in the column header.
  • Replied 8 August 2017, 10:40 am EST

    Hi Arodko,

    I can understand your use case.

    To accomplish this, You can use the flexGridFormatItem function of iOS FlexGrid.

    Specifically:
    1. Create another property "realDate" which parse the first date in the "stringDate" to Date object.
    2. Bind this "realDate" to the column instead of binding "stringDate".
    3. In the handler of flexGridFormatItem, cancel the default drawing of "realDate" and then draw the "stringDate" instead in the cell.
    In this way, we can sort the dates perfectly and meanwhile, show them as "stringDate". The sort indicator will show normally in the column header too.

    It seems that there is no way to upload an attachment in the forum. So please let me know if you have any questions about this. I will send you a complete example.

    I think it's useful to provide some more properties for column like "textBinding", "valueBinding", then we can easily display the cell as "textBinding" and use "valueBinding" to sort.
    We'll consider this in the future version. Thank you for the feedback.

    Regards,
    Aaron
  • Replied 8 August 2017, 10:40 am EST

    Great, thanks! Would you have a quick example of just drawing the string in the cell (in Swift)? I familiar with setting the cell color in formatItem, but not overriding the drawn text.
  • Replied 8 August 2017, 10:40 am EST

    Sure. Please try the code below in Swift :

    if (col.binding == "realDate") {
    let row:FlexRow = e.panel.rows.objectAtIndex(UInt(e.row)) as! FlexRow
    let data:CustomizedData = row.dataItem as! CustomizedData
    let s:NSString = data.stringDate
    let rect:CGRect = e.panel.getCellRectForRow(e.row, inColumn: e.col)
    s.drawAtPoint(CGPoint.init(x: rect.origin.x, y: rect.origin.y), withAttributes: nil)
    e.cancel = true
    return;
    }


    If you have any further concerns, please remain email address, I will send you the complete examples for iOS (obj-c, swift) or Android.

    We also discussed this requirement and planned to provide a new property for GridColumn in the next version :
    SortMemberPath (string) gets or sets the name of the property to use when sorting this column.
    Then we can accomplish the same requirement much more easily.

    Regards,
    Aaron
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels