Allow other characters when editing a column bound to decimal

2 posts, 1 answers
  1. Mircea
    Mircea avatar
    2 posts
    Member since:
    Jun 2015

    Posted 12 Jun 2015 Link to this post

    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.

  2. Answer
    Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 16 Jun 2015 Link to this post

    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
Back to Top