This is a migrated thread and some comments may be shown as answers.

Allow other characters when editing a column bound to decimal

1 Answer 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mircea
Top achievements
Rank 2
Mircea asked on 12 Jun 2015, 09:27 AM

Hi guys,

So, I'm developing a timesheets functionality for our product.

For the week view I have a grid and a model bound to it with some ids for project/client/item/etc. and each of the seven days of the week as decimals.

This works great when entering the time as decimal values, eg: 2.5 or 1.15. I use a clientTemplate to format it and display it as 02:30 or 1:09.

So far so good. Now comes the requirement that we want to be able to also input time as 2:30 or 1:09. The problem is the input box does not allow me to input the ":" sign. My workaround was to use string instead of decimal in the model for days. Got that to work nicely but now the sum aggreggates don't work anymore.

Since I know we cannot have custom aggreggates my question is: how can I sort this issue? I would prefer to have the model as decimal and a way to also input time as 00:00 since I can split them apart and make a decimal out of it to fit the model.

Thank you for your time.

 

Kind regards,

Mircea D.

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 16 Jun 2015, 07:50 AM

Hello Mircea,

I'm afraid that numeric text box does not support having multiple formats. A possible way to implement this will be to use a textbox (or maybe a MaskedTextBox with the appropriate mask) and use Grid edit event to attach to model's set event and manually convert the value from string to decimal. Something similar to the following:

function grid_edit(e) {
   e.model.bind("set", function(args) {                           
     if (args.field == "FieldToConvert" && args.value !== "" && typeof args.value === "string") {
            args.preventDefault();
       // the use of _set is required in order to skip the automatic convertion inside of it
       this._set("FieldToConvert", parseFloat(args.value));
     }
   });
 }

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Mircea
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or