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
How can I get the editOptions defined when calling navGrid
31/12/2009
05:30
Avatar
kuafusoft
Member
Members
Forum Posts: 27
Member Since:
31/12/2009
sp_UserOfflineSmall Offline

Firstly thanks for your great work. The jqGrid is really wonderful.

A question:

I want to edit a row (call editGridRow) via two ways:

1. navGrid.edit. Here I defined the editoptions when navGrid is called.

2. add a link to a column. Here I used the gridComplete to add a link to a column, such as 'name' column. when I click the 'name', a edit form will popup. but I can not use the defined editoptions. How can I get it?

Thanks.

03/01/2010
13:50
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Define the editoptions like this

var editoptions = { ... here all edit options};

then you can easy call

$("#mygrid").navGrid('pager',{...},{}, editoptions,...);

and

$("#mygrid").editGridRow(rowid, editoptions);

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.

04/01/2010
05:18
Avatar
kuafusoft
Member
Members
Forum Posts: 27
Member Since:
31/12/2009
sp_UserOfflineSmall Offline

Tony,

Thank you very much.

I want to add a link to a field to edit the row. I used the following code:

var disableAccount = function(formid){
    $("#users0_0account").attr('disabled', true);
};

var enableAccount = function(formid){
    $("#users0_0account").attr('disabled', false);
};

var users_editOptions = {
    beforeShowForm:disableAccount,
};

var users_addOptions = {
    beforeShowForm:enableAccount,
};

var users_gridComplete = function(){
    var gridId = '#list';
    grid_addEditLink(gridId, 'users0_0account', users_editOptions);
};

var initUsersColumns = function (jsonData){
    jsonData.editOptions = users_editOptions;
    jsonData.addOptions = users_addOptions;
    jsonData.gridComplete = users_gridComplete;
    return jsonData;
};

anyway, the initUserColumns will be called to set the colModels.

in a common.js, I define the relative functions:

var grid_getOptions = function(action, prop){
    var defaultNavOptions = {view:true};
    var defaultEditOptions = {top:100, left:500, closeOnEscape:true, bottominfo:"Fields marked with (*) are required",};
    var defaultAddOptions = {top:100, left:500, closeOnEscape:true, bottominfo:"Fields marked with (*) are required",};
    var defaultDelOptions = {};
    var defaultSearchOptions = {
            multipleSearch:true,
            gridModel:false,
            gridNames:true,
            formtype:"vertical",
            enableSearch: true,
            enableClear: true,
            autosearch: false,
            filterModel:[],
        };
    var defaultViewOptions = {top:100, left:500, closeOnEscape:true,};
    var options = {};
    switch(action){
        case 'edit':
            options = $.extend(defaultEditOptions, prop || {});
            break;
        case 'add':
            options = $.extend(defaultAddOptions, prop || {});
            break;
        case 'nav':
            options = $.extend(defaultNavOptions, prop || {});
            break;
        case 'search':
            options = $.extend(defaultSearchOptions, prop || {});
            break;
        case 'view':
            options = $.extend(defaultViewOptions, prop || {});
            break;
        case 'del':
            options = $.extend(defaultDelOptions, prop || {});
            break;
           
    }
    return options;
};

var grid_edit = function(gridId, rowId, prop){
    $(gridId).jqGrid('editGridRow', rowId, prop);
};

var grid_addEditLink = function(gridId, col, prop){
    prop = grid_getOptions('edit', prop);
    gridId = gridId || '#list';
    var ids = jQuery(gridId).jqGrid('getDataIDs');
    for(var i=0;i < ids.length;i++){
        var cell = jQuery(gridId).getCell(ids[i], col);
        var link = "javascript:grid_edit('" + gridId + "'," + ids[i] + "," + Object.serialize2Str(prop) + ")";// jQuery('" + gridId + "').editGridRow('"+ids[i]+"')";
        var addLink = "<a href=\\"" + link + "\\">" + cell + "</a>";
        jQuery(gridId).setCell(ids[i], col, addLink);
    }
};

But I can not serialize the function handles in editOptions(always be null, maybe I should improve the serialize2Str function which is get by google:)), so I changed the beforeShowForm to 'disableAccount'/'enableAccount' (just a string, the function name). Of couse it can not work well.

Can the jqGrid change the function name to function handle? I think it's not difficult to get the parameter type of the beforeShowForm (and other event parameters), can you give me any suggestion?

Thank you very much. and please forgive my poor english.

04/01/2010
05:25
Avatar
kuafusoft
Member
Members
Forum Posts: 27
Member Since:
31/12/2009
sp_UserOfflineSmall Offline

I should explain the environment of my application. PHP + mySql + jQuery.

I want to use only one list.php to display all grid. the grid definition will be defined in other .php files. The list.php get the grid name from $_REQUEST then gets the grid definition with ajax and display it. Different grid has different options. So I have to pass some parameters to the grid definition. For example, for users management, when edit a user, we should disable the account, but when add a new user, we must enable the account. This action is done in beforeShowForm. But for other grid, there's no such problem. So I have to set the editOptions and some other options as parameters to pass to the list.php.

04/01/2010
07:19
Avatar
kuafusoft
Member
Members
Forum Posts: 27
Member Since:
31/12/2009
sp_UserOfflineSmall Offline

Tony,

I improved the function serialize2Str to get the function name from function handle. So I think the code can work now. but I don't think it's a good solution. I still suggest to modify the jqgrid code to improve the event handle(if  the event is function name, then we should transfer to function handle).

Thank you very much.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
108 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