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_Related Related Topics sp_TopicIcon
How do I add columns to the edit modal that are read-only?
28/01/2014
01:33
Avatar
dwschulze
United States
Member
Members
Forum Posts: 11
Member Since:
24/01/2014
sp_UserOfflineSmall Offline

I want to add a couple of columns to the edit dialog that are read-only.  This is to remind the users which row of data they are editing.  (The style I'm currently using highlights the selected row very faintly so it's hard to tell which row of data you are editing.)

Is there a way to add columns to the edit modal and make them read-only?

28/01/2014
04:38
Avatar
Lonewolf217
Member
Members
Forum Posts: 32
Member Since:
22/05/2013
sp_UserOfflineSmall Offline

you can use an event like beforeInitData() in the edit function to make the form elements disabled.  For example, make the column you want as read only to be a text editable field, then in beforeInitData, set

$("#"+columnname).prop('readonly',true);

It will still show up as an input element but it wont be editable.  Of course you can also go the extra step of hiding the input element entirely and replacing it with a span of text. I think this will work, but its late and i didn't test it so play with it

val = $("#"+columnname).val();

$("#"+columnname).hide().after('<span>'+val+'</span>');

28/01/2014
05:04
Avatar
dwschulze
United States
Member
Members
Forum Posts: 11
Member Since:
24/01/2014
sp_UserOfflineSmall Offline

What is columnname if my colModel has a serial number column like this:

colModel: [

    { name: "serialNumber", label: "Serial Number", editable:true},

    ...

], 

Doing 

$("#" + "serialNumber").prop('readonly',true);

doesn't work.

Lonewolf217 said:

you can use an event like beforeInitData() in the edit function to make the form elements disabled.  For example, make the column you want as read only to be a text editable field, then in beforeInitData, set

$("#"+columnname).prop('readonly',true);

It will still show up as an input element but it wont be editable.  Of course you can also go the extra step of hiding the input element entirely and replacing it with a span of text. I think this will work, but its late and i didn't test it so play with it

val = $("#"+columnname).val();

$("#"+columnname).hide().after('<span>'+val+'</span>');


28/01/2014
05:41
Avatar
Lonewolf217
Member
Members
Forum Posts: 32
Member Since:
22/05/2013
sp_UserOfflineSmall Offline

right click and inspect the editable element in the browser, it will tell you exactly what the ID is. (if you use chrome/firefox or firebug)

Depending on your version of jquery, you may need to use .attr() instead of .prop()

28/01/2014
15:23
Avatar
dwschulze
United States
Member
Members
Forum Posts: 11
Member Since:
24/01/2014
sp_UserOfflineSmall Offline

Here's what I've tried.  None of them work:

beforeInitData : function(formid) {

$("#formid").prop('readonly',true);

// $("#jqgh_prodTable_serialNumber").prop('readonly',true);

// $("#jqgh_prodTable_serialNumber").attr('readonly',true);

// $("#prodTable_serialNumber").attr('readonly',true);

// $("#prodTable_serialNumber").prop('readonly',true);

// $("#" + "serialNumber").prop('readonly',true);

}

28/01/2014
16:25
Avatar
Lonewolf217
Member
Members
Forum Posts: 32
Member Since:
22/05/2013
sp_UserOfflineSmall Offline

http://www.trirand.com/jqgridw.....ing#events

can you try using beforeShowForm() instead of beforeInitData()

Just got a chance to try it myself and it should work when using the new event. 

28/01/2014
17:54
Avatar
dwschulze
United States
Member
Members
Forum Posts: 11
Member Since:
24/01/2014
sp_UserOfflineSmall Offline

Changing beforeInitData to beforeShowForm doesn't work either.  I'll try to find a style that shows the highlighted row more clearly and rely on the users to recognize which row they are editing

This ability to add a read-only column to the edit modal should be added as a feature request for a future release of jqGrid.

28/01/2014
20:35
Avatar
Lonewolf217
Member
Members
Forum Posts: 32
Member Since:
22/05/2013
sp_UserOfflineSmall Offline

strange, i had tried it on my own and it did successfully make the text field readonly in edit mode

29/01/2014
06:59
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello boys,

Why you do this so complex?

There is a more easy way.

If you have read the docs here you should see that this is much easy

colModel : [

...

{name:serialfield, ... editoptions: { readonly : true, /* or readonly : 'readonly' */ ... } ...}

...

]

Regards

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:
51 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