Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Changing Format before save
06/08/2009
10:51
Avatar
Romyn
Member
Members
Forum Posts: 45
Member Since:
13/06/2009
sp_UserOfflineSmall Offline

Hi,

I had a search and looked through the new wiki - I take it it's new anyway - very nice! - but am a bit confused to what I should being doing to perform the following.

I have a number of columns/cells whose value is held in seconds but displayed as either HH:MM:SS or MM:SS. This works fine on the display side using a couple of custom formatters but the problem comes when I try and add/edit (both inline and via dialog form).

I don't know how to take the input which is a string and convert that into an integer. I have the functions to do the conversions but I don't know where/how to apply them. How/where do I grab the value and change it in the celledit, addnew and edit forms.

I'm sure this is pretty strightforward but would really appreciate some pointers.

Thanks and regards

Romyn

06/08/2009
10:57
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

06/08/2009
11:08
Avatar
Romyn
Member
Members
Forum Posts: 45
Member Since:
13/06/2009
sp_UserOfflineSmall Offline

Thanks Tony,

That looks to be just the job. I tried it quickly but couldn't get it to work - what version to I need to be running for this?

Cheers

Romyn

06/08/2009
11:18
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Could you post the code for the format and unformat functions - or better post all again with grid configuration.

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

06/08/2009
11:41
Avatar
Romyn
Member
Members
Forum Posts: 45
Member Since:
13/06/2009
sp_UserOfflineSmall Offline

Hi,

The relevant bits are:-

The col model:

{name:'sdelay', index:'sdelay', width:60, align:'center',editable:true, editoptions:{dataInit:function(el){$(el).mask(”99:99:99″);}, defaultValue:'00:00:00'}, formatter: fmt_HMS, unformat: unfmt_HMS},

The format function:

var fmt_HMS = function(cellval,options,rowdata) {
    formatted_cellval = secsToHMS(cellval);
    return formatted_cellval;
}

The unformat function:

var unfmt_HMS = function(cellval,options) {
    unformatted_cellval = HMSToSecs(cellval);
    return unformatted_cellval;
}

Support functions:

function HMSToSecs(duration) {
    var d_array = duration.split(”:”);
    var s = (parseInt(d_array[0],10)*3600) + (parseInt(d_array[1],10)*60) + parseFloat(d_array[2]);
    return s;
}

function secsToHMS(secs) {
var h = parseInt(secs/3600,10);
var m = parseInt((secs-(3600*h))/60,10);
var s = parseInt((secs-(3600*h)-(60*m)),10);
var hms = PadDigits(h,2) + ':' + PadDigits(m,2) + ':' + PadDigits(s,2);
return hms;
}

PadDigits just adds leading 0's when needed – and the .mask is a masked edit plugin.

I believe I'm running the last version for which a min'ed pack was available – not the latest from GitHub – it doesn't even get into the unformat function (an alert in there doesn't fire) so this could be why.

Romyn

06/08/2009
12:04
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Romyn,

Thanks - it is a bug in formedit module. Fixed. Will publish a bug fix release at end of this week.

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

06/08/2009
12:06
Avatar
Romyn
Member
Members
Forum Posts: 45
Member Since:
13/06/2009
sp_UserOfflineSmall Offline

I've just downloaded the latest pack again (not the GitHub one) and it is different so I'm not completely up-to-date on that by the looks of things.

However using the latest a TreeGrid I have gets stuck on “Loading” so something has changed in that that I need to fix first – new syntax or something?

I'll try and do that and then see if the unformat function gets called. (Can't get to it until I fix the TreeGrid as that is the launch point for the other grids with the meat in them)

Regards

Romyn

edit - just seen your other reply. Thx - I'll download again in a few days.

06/08/2009
12:19
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello again,

Tottaly confused. It is a my fault at all. All will be fixed in the 3.5.1 and documented  again - found the problem.

Also What is the problem with treeGrid?

Thanks

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

06/08/2009
12:30
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Here is the problem: (instead I found another in formedit regrading this)

You define the  fmt_HMS

as var fmt_HMS = function….

Which I think it is after the grid

To work this you should

1. Define this variable before the grid

2. or define the function as follow:

function fmt_HMS (…) {

}

and not var fmt_HMS = function.

Also there is a bug into the documentation

The cellvall parameter is a jQuery object, but not a value

with other words you should

function fmt_HMS (cellval, options) {

var myval = $(cellval).html();

// do something with this and

return newvalue;

}

BUT THIS WIIL BE CHANGED IN ORDER TO HAVE EQUAL STANDART PARMETERS  IN BOTH FORMAT AND UNFORMAT FUNCTIONS

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

07/08/2009
00:09
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

I made the needed fixes in the GitHub. Also fixed some other bugs related for datetype as function

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

07/08/2009
13:14
Avatar
Romyn
Member
Members
Forum Posts: 45
Member Since:
13/06/2009
sp_UserOfflineSmall Offline

I'll admit to being pretty confused myself now.

I've downloaded the latest GitHub files and made the changes to how the functions are defined - (don't know where the var versions came from - must have been done that way in the examples I used).

Anyway with those changes made I'm still having some trouble. The ideal scenario I want to get to is to store as Seconds, display as HH:MM:SS and edit using a Mask in the for __:__:__

To that end I've put together a simple page with a grid that has various differently configured columns - and celleditting enabled so just clicking in and out of the cell should show the effects.

http://www.thekmz.co.uk/GEPlug.....dtest4.htm

Simple - no formatting at all

fmt - just the formatter

fmt/unfmt - formatter and unformatter

fmt/mask - formatter and mask

fmt/unfmt/mask - formatter, unformatter and mask

The fmt/unfmt column works as designed (except when the value is 0 which I can't suss out?) - but I want to then add the mask to that but that doesn't seem to work. I also appreciate that some of the columns shouldn't work correctly but they are there just to show how I build up through adding the various options)

(also tried the var myval = $(cellval).html(); thing you mentioned but that didn't work for me at all so I went back to the old style).

Sorry this is so confused but it reflects the state of my little brain...

(I might be better off going back to storing the value as a HH:MM:SS string but I want to avoid that if I can)

Regards

Romyn

10/08/2009
05:32
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

This example is very helpfull.

OK - the problem - Which is the first chicken or the egg.

In order to understand what is happen:

1. You format the hour (represented as number) and this work ok.

2. You try to edit the formated data, but before to display it you make a unformat. (When we edit the data the first what we do is to unformat it).

3. You have the unformated data.

4. After unformat we applay all the events - including dataInit where you apply the mask plugin, but this data is alredy number and it can not be used correctly in the plugin.

5. The result - inconsitent display.

I think that in this case you should not the unformat, but rather use some events in cellEditing to post the number and then this number will be correcly converted from format function.

If you have difficulties please let me know.

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
83 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information