0

Can any one suggest me how can I get parent row id in the custom validation function of sub grid?

This is a my code

 subGrid: true,
                subGridRowExpanded: function (subgrid_id, row_id)
                {

                    var subgrid_table_id;
                    subgrid_table_id = subgrid_id+"_t";
                    var subgrid_pager_id = subgrid_id+"_p";
                    jQuery("#"+subgrid_id).html("<table id="+subgrid_table_id+"  class=scroll></table><div  id="+subgrid_pager_id+" ></div>");
                    jQuery("#"+subgrid_table_id).jqGrid(
                    {
                        url:"form_subgrid_ajax_296.php?id="+row_id+"&child_form_id=296",
                        editurl:"../ajax/common_subgrid_edit_296.php?form_id="+sub_grid_id+"&parent_id="+row_id,
                        datatype: "json",

                        colNames: ['ID','PESO'],
                        colModel: [{name:'id',index:'id',editable:false,hidden:true},
                            {name:'peso',
                    index:'peso',
                    formoptions:{elmsuffix:''},editrules:{required:true,custom:true, custom_func:customNumberChk},editable:true,
                                hidden:false,
                                search:true,
                                editoptions: {size:80, maxlength: 1000}
                                }],
                        sortorder: "asc",
                        height: 300,
                        loadonce: false,
                        width: 500,
                        rowNum:10, 
                        rowList:[10,20,50],
                        sortname: 'id',
                        sortorder: "asc",
                        cellEdit: false,
                        cellsubmit: "clientarray",
                        caption:"Child",
                        pager: subgrid_pager_id
                    });
                    jQuery("#"+subgrid_table_id).jqGrid
                    (
                    "navGrid",
                    "#"+subgrid_pager_id,
                    {
                        edit:true,
                        add:true,
                        del:true,
                        search:false
                    },
                    {
                        width:780,
                        recreateForm:true
                    },
                    {
                        width:780,
                        recreateForm:true
                    }
                  );
                }

Now look at the name:'peso',index:'peso', .I have used custom function customNumberChk.

This is my custom function

function customNumberChk(value,colname)
{

}

I want rowid in this function.

Nisarg
  • 3,024
  • 5
  • 32
  • 54
  • which kind of subgrid you use? [Subgrid as Grid](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:subgrid_as_grid)? – Oleg Jun 27 '13 at 10:36
  • yes, I am using Subgrid as Grid – Nisarg Jun 27 '13 at 10:39
  • in the case you have the rowid as parameter of `subGridRowExpanded` callback and I don't full understand your question. Probably the problem exist in the form hos you organized your code. You should include the code which you use currently. – Oleg Jun 27 '13 at 10:45
  • I found that you included the code in your question just accidentally. Please write short comment to inform about the changes. It will produce notification. – Oleg Jun 27 '13 at 15:19

1 Answers1

0

It's important just the place where you define the function customNumberChk used for custom validation. JavaScript allows to access any variable defined in the outer scope. One name such functions as closure (see the answer for more information). So you can for example define customNumberChk inside of subGridRowExpanded anonymous callback function:

subGridRowExpanded: function (subgrid_id, row_id) {
    var subgrid_table_id;
    function customNumberChk (value, colname) {
        // one can use here ANY variable from the outer scope
        // inclusive subgrid_id, row_id, subgrid_table_id and so on
    }
    ...
    jQuery("#"+subgrid_table_id).jqGrid({
        ...
        colModel: [...
            {name:'peso',
             ...
             editrules:{required:true,custom:true, custom_func: customNumberChk}
            }
        ...
    });
    ...
}

In the same way you can don't define customNumberChk function at all and use custom_func defined as anonymous function:

subGridRowExpanded: function (subgrid_id, row_id) {
    var subgrid_table_id;
    ...
    jQuery("#"+subgrid_table_id).jqGrid({
        ...
        colModel: [...
            {
                name:'peso',
                ...
                editrules: {
                    required: true,
                    custom: true,
                    custom_func: function (value, colname) {
                        // one can use here ANY variable from the outer scope
                        // inclusive subgrid_id, row_id, subgrid_table_id
                        // and so on
                    }
                }
            }
        ...
    });
    ...
}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798