Rounding Time to 15 mins with JS. Need grid help

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Rounding Time to 15 mins with JS. Need grid help

Post by Jaymer »

I have an app that used to use 2 fields, Hours & Mins to indicate time on a job.
1 good thing about that approach was Mins was a Choices field with 0, 15, 30, 45 as the only 4 choices.
But because of entry inline in a Grid, I'd rather have a single Time field, but I want to round all time into 15 minute chunks.

I was thinking a JS function might be the easiest - no traffic back & forth to the server, let this happen in the browser Local on the user's machine.
(there's lots of this going on, so I don't want to add traffic & server processing)

Forum threads indicate I can trap when a field loses focus. And I can setValue back into the Kendo field.
All time needs to round up to next .25 increment.
Multiply time x 4, then round up, then div by 4.

Code: Select all

var f = parser.getField("Day1");
$("#" + f.getId ()).focusout (function () {
   var Value1 = parser.getField("Day1").getValue ();
   f.setValue ( Math.ceil( Value1 * 4)/4 );
});
Works perfectly in a form, but
How do I get this to work in a Grid?
I'll have 7 fields (each day of week) and I know I'll need this 7 times (Day1 thru Day7).
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Post Reply