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
Key data needs to be added to Detail rows of Master/Detail grids
02/09/2009
14:13
Avatar
Sloan
St. Cloud, MN
Member
Members
Forum Posts: 11
Member Since:
13/08/2009
sp_UserOfflineSmall Offline

I've got a master/detail pair of grids. There is a parent key(actually 2 fields) in the detail grid, referring to the corresponding row in the master grid. In the detail grid, I have these fields hidden and not editable.

When adding or editing a row, neither field is included in the data sent to the server. Here's the code for the detail table:

    jQuery(”#ColumnList”).jqGrid({
        url:'ColGrid_XML.asp',
        editurl: 'ColEdit_XML.asp',
        datatype: 'xml',
        mtype: 'POST',
        colNames:['ID','DB','Table','Order','Name','Type','Size','Default','Nulls?','Indexed?','Updated','Created'],
        colModel :[
            {name:'tdr_ID', index:'tdr_ID', width:0,search:false, editable: false,hidden:true},
            {name:'tdr_td_DB', index:'tdr_td_DB',width:0,sortable:false,search:false, editable: false,hidden:false},
            {name:'tdr_td_Name', index:'tdr_td_Name', width:0,sortable:false,search:false, editable: false,hidden:false},
            {name:'tdr_RowOrder', index:'tdr_RowOrder', width:35, align:'left',search:false, editable: true,editrules:{edithidden:false, required:false, integer:true, minValue:0},editoptions:{size:"20",maxlength:"20"}},
            {name:'tdr_Name', index:'tdr_Name', width:140, align:'left',search:true,sortable:false, editable:true, edittype:'text',editoptions:{size:"20",maxlength:"20"}},
            {name:'tdr_Type', index:'tdr_Type', width:120, align:'left',search:true,sortable:false, editable:true, edittype:'select',editoptions:{value:'int:int;number:number (Enter Decimals in Size);varchar:varchar (Enter Length in Size);text:Text;date:date;identity:(Special) Identity;parentid:(Special) Parent ID;updated:(Special) Date Last Updated;created:(Special) Date Created'}},
            {name:'tdr_Size', index:'tdr_Size', width:120, align:'center',search:false,sortable:false, editable:true, edittype:'text',editoptions:{size:"10",maxlength:"20"}},
            {name:'tdr_Default', index:'tdr_Default', width:80, align:'center',search:false,sortable:false, editable:true, edittype:'text',editoptions:{size:"30",maxlength:"20"}},
            {name:'tdr_Nulls', index:'tdr_Nulls', width:60, align:'center',search:false, editable:true,formatter:'checkbox',edittype:"checkbox", editoptions:{value:"Y:N"},sortable:false},
            {name:'tdr_Indexed', index:'tdr_Indexed', width:60, align:'center',search:false, editable:true,formatter:'checkbox',edittype:"checkbox", editoptions:{value:"Y:N"},sortable:false},
            {name:'tdr_Updated', index:'tdr_Updated', width:120, align:'center',search:false, sorttype:'date', datefmt:'Y-m-d', editable:false,sortable:false},
            {name:'tdr_Created', index:'tdr_Created', width:120, align:'center',search:false, sorttype:'date', datefmt:'Y-m-d', editable:false,sortable:false} ],
        pager: jQuery('#ColPager'),
        rowNum:10,
        rowList:[5,10,20,30,50],
        height:'230px',
        altRows:true,
        multiselect:false,
        hiddengrid:false,
        sortname: 'tdr_id',
        sortorder: 'asc',
        closeAfterAdd:true,
        closeAfterEdit:true,
        viewrecords: true,
        multiselect:false,
        imgpath: 'img/images',
        caption: 'Columns'
    }).navGrid('#ColPager',{add:true,edit:true,del:true,width:'400px'});

The fields tdr_td_DB and tdr_td_Name are the fields that link back to the parent table. I tried adding onClickSubmit, which doesn't seem to ever be called. I've been testing with “alerts” in that code than never show up.

Any help would be greatly appreciated!!

Sloan

Sloan Thrasher

02/09/2009
17:37
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi Sloan!

It seems to me, if you'll use "hidden: true, editable: true, editrules: { edithidden: false}" instead of "editable: false,hidden:true", your problem will be solved.

Regards

Oleg

03/09/2009
00:20
Avatar
Sloan
St. Cloud, MN
Member
Members
Forum Posts: 11
Member Since:
13/08/2009
sp_UserOfflineSmall Offline

Thanks Oleg.

That helps on edit, but those two fields are empty when a new row is added.

So I still need to find a way to populate them when the form is called, or just after the submit button is clicked on the form.

Thanks!

Sloan

Sloan Thrasher

03/09/2009
02:54
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Sloan,

I see different ways which can help you. First of all, if new row added send to server, server must returns back at least id. So, you can use one constructed parameter (tdr_ID + '_' + tdr_td_DB). Id will be always sending to server and back and id must be not a part of colModel at all. If tdr_td_DB is nullable, you can use strings like (tdr_ID + '_NULL') in such cases. They will be unique and can be an id. And such constructed Ids can be easy decoded to your real two Ids by server.

Second, if server generates or updates more data fields after data modification, you can use afterSubmit function, which be called by navGrid after Add or Edit action. If one version of such function enough for you in your whole program, you can set with so way:

$.extend($.jgrid.edit, {..., afterSubmit: function(response, postdata) {
            var res = $.secureEvalJSON(response.responseText);
            if (typeof res === "string") {
                postdata.RowVersion = res;
                return [true, ""];
            }
            else {
                postdata.RowVersion = res.RowVersion;
                return [true, "", res.Id];
            }
        }, ...});

or you can set it directly as a parameter of navGrid function:

jQuery(”#ColumnList”).jqGrid({
        url:'ColGrid_XML.asp',
        editurl: 'ColEdit_XML.asp',
        datatype: 'xml',
        mtype: 'POST',

        .....

caption: 'Columns'

    }).navGrid('#ColPager',
                  {add:true,edit:true,del:true,width:'400px'},  // navGridOptions
                  {},   // Edit options
                  {afterSubmit = function(response, postdata) {
                        var res = $.secureEvalJSON(response.responseText);
                        postdata.RowVersion = res.RowVersion;
                        return [true, "", res.Id];
                  }});  // Add options

In the example serever send back to the client JSON encoded data Id and RowVersion (timestamp of data row, which I use for concurency check).  Global version of afterSubmit detects Add or Edit situation based on respond data type. My server send back a string with RowVersion value back for the Edit action and an Object {Id,RowVersion} as a response to Add action. You can solve your problem with a close way.

Regards
Oleg

03/09/2009
06:00
Avatar
Sloan
St. Cloud, MN
Member
Members
Forum Posts: 11
Member Since:
13/08/2009
sp_UserOfflineSmall Offline

Thanks Oleg,

But the problem is that when jqGrid sends the added row to the server, the data has to include the key of the master table row.

For Example:

Master data:

    ID, DBName, TableName,  Description

In this case, ID is a unique ID for the Master table


Detail Data:

    ID, Master_DBName, Master_TableName,  FieldName, FldType, etc.

In this case, ID is a unique ID for the Detail table


Where DB_Name = Master_DBName and TableName = Master_TableName

When jqGrid adds a row, Master_DBName and Master_TableName are blank (as with all the row's fields), so I need to be able to insert the proper key from the master grid/table. Otherwise, the asp file on the server won't know which master record to associate with the detail row.

In other words, I need to populate the fields before the data is sent to the server.

Also, I'll need to get the value(s) of the parent key fields of existing rows in order to figure out the value to put into these parent key fields. I saw an XML example where user data was passed outside the rows, in the same area where things like the page number and such are located. That might be the way to pass the parent key to the grid. (all rows in the detail grid would have the same parent keys).

Sorry to be so slow, and thanks for your patience!

Sloan

Sloan Thrasher

03/09/2009
06:32
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi Sloan,

it's a little another problem, but it could be also easy solved. You can add in you edit/add options as a parameter of navGrid a function onclickSubmit in your Detail grid. For example,

var grid = jQuery('#master').jqGrid({

...

var urlEditDetail='ColEdit_XML.asp';

var gridDetails = jQuery('#detail').jqGrid({

...

}).navGrid('#ColPager',
                  // navGridOptions:
                  {add:true,edit:true,del:true},
                  // Edit options:
                  {onclickSubmit: function(rp_ge, postdata) {
                       var sel_testcluster_id = grid.getGridParam('selrow');
                       rp_ge.url = urlEditDetail + '/' + sel_testcluster_id;
                   }},
                  // Add options:
                  {onclickSubmit: function(rp_ge, postdata) {
                       var sel_testcluster_id = grid.getGridParam('selrow');
                       rp_ge.url = urlEditDetail + '/' + sel_testcluster_id;
                   }});

So you add onclickSubmit in Edit/Add navigation bar of the Detail grid. If the event take palce, you get Id of from selected row of Master grid and place if either as a part of postdata or in the url like in my example.

Best regards

Oleg

03/09/2009
14:39
Avatar
Sloan
St. Cloud, MN
Member
Members
Forum Posts: 11
Member Since:
13/08/2009
sp_UserOfflineSmall Offline

Thank You! Thank You! Thank You! Thank You! Thank You! 

I tried to get onclickSubmit working for a couple of days. I didn't realize that it went inside the navGrid. That's such a great help!

After reading your post, I got it up and running in about 30 minutes

Again, thank you for your help and your patience!

Sloan

Sloan Thrasher

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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