Dataform Using Numeric Format Strings

1 Answer 156 Views
DataForm NumericInput
Calin
Top achievements
Rank 1
Calin asked on 02 Mar 2022, 06:30 PM

I have an integer property in the source of a DataForm, and I'm looking for an easy way to apply string formatting in the UI. I would like this to be applied regardless of DataForms readonly status. So a number like 10005 will show as 10,005 or 10.005. I'm fine with the formatting to be disabled during editing.

I've explored a bit with iPropertyConverters, or adding a string property that uses the integer properties values, but I haven't had any success with seeing the formatted values in both readonly statuses and using the NumberPickerEditor.

Any help would be greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 02 Mar 2022, 07:22 PM

Hello Calin,

You can use the DisplayValueFormat attribute on the property for that numeric value. See the DisplayValueFormat Attribute documentation for more information.

In that doc's example, you'll see a double value for Votes. You can use a format specifier where the numerical placement is in the format string (for example "{0:N3}" will use N3 formatting that you gave an example of).


Lance | Manager Technical Support
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Calin
Top achievements
Rank 1
commented on 07 Mar 2022, 11:04 PM

I've tried this and it does not seem to work for me. I made a fresh project too to make sure and still I got the same results.

Lance | Manager Technical Support
Telerik team
commented on 08 Mar 2022, 12:03 AM

I've attached my project so you can compare against.

Calin
Top achievements
Rank 1
commented on 08 Mar 2022, 04:39 PM

The project you sent me didn't work for me either, but I think there was a mistake in the example you sent me. The number picker editor was not correctly set. When it's set properly it will honor the display value format. After going over the documentation, it looks like the display value format works with the number picker editor but not integer editor.

In my case, I don't think I want to use the NumberPickerEditor, since I want to be able to use just a normal number keyboard and not increment everything by button presses. I also noticed that when the dataform is read only the number picker editor doesn't show at all, so the display format will not be honored. Are there any other options for me? I would like the user to enter in a number using a number keyboard, and for it to be displayed back to the user with the thousand separators shown, regardless of its read only status.

I am curious though how to work with the NumberPickerEditor. I can't find documentation on it. Can you share a link that explains how to set the limits or increment steps of the editor?

 

 

Lance | Manager Technical Support
Telerik team
commented on 08 Mar 2022, 06:22 PM

You can find a list of the Editors here Xamarin DataForm Documentation | Editors | Telerik UI for Xamarin

You cannot use an IntegerEditor with a double value, it has to be an int (or have a converter). I suspect maybe the platform conversion is  changing the behavior. The options available for non-integers like double and decimal are NumberPickerEditor and DecimalEditor.

Finally, you could build your own custom Editor with native platform elements, though keep in mind that this is not trivial and you'll want to look at both of our Sample applications for guidance on each implementation and start with the Custom Editors documenation.

Further Assistance: If you have any further issues or would like to discuss the read-only conditions, I highly recommend opening a Support Ticket (you have Priority Support) so that you can work with the Xamarin engineering team. Please provide a runnable sample app that demonstrates the issue to prevent long delays (i.e. update my demo and attach it to your opening post).

Tags
DataForm NumericInput
Asked by
Calin
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or