0

In my ASP.NET MVC application, I have JQGrid and its SubGrid but I noticed on onSelectRow event it is not detecting Subgrid rows until I expand main grid rows. I am trying to select main grid row and on select, all sub grid row's checkbox should be selected. But it is not finding any SubGrid. But when I expand then it works. Am I missing any property of Grid or Subgrid?

$("#MyGrid").jqGrid({
                    datatype: 'local',
                    colModel: [
                        {
                            name: 'ColSelected', label: ' ', width: 40, sortable: false,
                            formatter: 'checkbox', align: 'center', formatoptions: { disabled: false },
                            editable: true, edittype: "checkbox", editoptions: { value: "Yes:No", defaultValue: "Yes" }
                        },
                        { name: 'ColName', label: 'Column Name', width: 340, editable: false, sortable: false }],
                    height: '100%',
                    autowidth: true,
                    multiselect: false,
                    beforeSelectRow: function (rowid, event) {
                        //some of my code
                        return true;
                    },
                    onSelectRow: function (rowid, status, event) {
                        //some of my code

                    },
                    gridComplete: function () {
                       //some of my code
                    },
                    loadComplete: function () {
                       //some of my code
                    },
                    subGrid: true,
                    subGridOptions: {
                        "plusicon": "ui-icon-triangle-1-e",
                        "minusicon": "ui-icon-triangle-1-s",
                        "openicon": "ui-icon-arrowreturn-1-e",
                        "reloadOnExpand": false,
                        "selectOnExpand": false
                    },
                    subGridRowExpanded: function (subgrid_id, row_id) {
                        var subgrid_table_id = subgrid_id + "_t",
                            pager_id = "p_" + subgrid_table_id,
                            localRowData = $(this).jqGrid("getLocalRow", row_id);
                        $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "'></table><div id='" + pager_id + "'></div>");
                        $("#" + subgrid_table_id).jqGrid({
                            datatype: "local",
                            data: localRowData.LanguageNames,
                            colNames: [' ', 'Languages'],
                            colModel: [
                                {
                                    name: 'ColSelected', label: ' ', width: 40, sortable: false,
                                    formatter: 'checkbox', align: 'center', formatoptions: { disabled: false },
                                    editable: true, edittype: "checkbox", editoptions: { value: "Yes:No", defaultValue: "Yes" }
                                },
                                { name: 'Language', label: 'Languages', align: 'center', width: 150 }
                            ],
                            idPrefix: "s_" + row_id + "_",
                            pager: "#" + pager_id,
                            autowidth: true,
                            sortname: "num",
                            sortorder: "asc",
                            height: "55",
                            beforeSelectRow: function (rowid, event) {
                            //some of my code
                                return true;
                            },
                            onSelectRow: function (rowid) //some of my code
                            },
                            loadComplete: function () {//some of my code
                            }
                        }).jqGrid('navGrid', "#" + pager_id, { edit: false, add: false, del: false });
                    }
                });
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ritesh Gupta
  • 171
  • 1
  • 2
  • 19

1 Answers1

0

If I correctly understand the problem you can use the options selectOnExpand and selectOnCollapse (which are sbgrid options). By default they are false.

I recommend you to consult the docs here

Tony Tomov
  • 3,122
  • 1
  • 11
  • 18
  • As I said if use **selectOnExpand** event then all HTML of subgrid will be prepared and I don't have problem there. But I want all subgrid table row and table data without expanding. – Ritesh Gupta Jun 26 '23 at 06:56
  • Not sure I understand, but data is loaded only if you expand it. You set reloadOnExpand to false, which is a solution, but the data should be already be loaded (i.e you should expand it once to get the html) – Tony Tomov Jun 26 '23 at 07:29