I have a XamDataGrid bound to business objecta which exposes all column data as strings. Sorting columns with numbers isn't working in this context. What is the best way to handle this scenario? Change the Business object property to type int or handle this in some other way? Please let me know.
Thanks,
Shravan
To add to what Galina suggested...
Changing the data type in the object model would be the best solution. However, if you prefer to keep the underlying data as strings, you can also assign the string to a numeric editor by specifying the type, the editor type, and optionally a number formatting. You can do this by providing a Field definition in a FieldLayout declaration. As Galina suggested you can set the type to Int. In the following example I am setting the type to Double as well as explicitly assigning a XamNumericEditor with formatting (this part can be left out if you want).
<igDP:FieldLayout.Fields> <igDP:Field x:Uid="Price" Name="Price"> <igDP:Field.Settings> <igDP:FieldSettings EditAsType="{x:Type sys:Double}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamNumericEditor}" > <Setter Property="Mask" Value="{}{currency:7.2:c}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
Curt, Thanks for your response. The complete solution to my problem is still not clear to me. I have numbers from my Business object represented as strings for which I have defines a comma separator DataConverter, such that it displays comma seperated numbers when the grid renders. Could I use the Mask on the XamNumericEditor for achieveing the same comma separation? Also, the requirement is to nothing when the value is 0, so right now, in my converter, I return null when I encounter 0 value for this column in the Business obj. Can you help further on this?
Hello curtis, Any update on this? We have a Qa drop tomorrow for which I have committed to fix this issue. Please can you let me know of a way this could be achieved?
I hope to have a solution for you by tonight or tomorrow morning. Thanks!
Hello,
Attached is your project with the fix I proposed above. Now sorting works on the column as numbers rather than strings.
Hi Curtis,
I have a similar requirement only thing is I do not want to show the decimal places on the UI. e.g. 123,456.00 is not a valid value for me as I need to show only an integer number and not a decimal number. 123,456 is something I want to show
Can you please let me know if any specific formatting is available which would allow me to sort the column as numbers still it will show only numbers and not the decimal ones?
Hello Sandeep,
Thank you for your post. I have been looking into it and I can say that if you chnage the Mask of the TotalTrades Field's XamNumericEditor to "{}{currency:7.0:c}" only the integer part of the values will be shown and the Field will still be sorted as number, as you want.