As per kind request from Tony Tomov I am posting the question here, hoping you guys can help me.
I am just starting with jqGrid and JS in general, so a fair amount of hand-holding might be required to help me get over this problem.
I have one ‘select’ dropdown field where user selects from a range of categories / names, based on user selection I need to populate the next ‘select’ dropdown with corresponding set of sub categories. All in inline edit.
So select first option, which in my example is department name, and then based on that department name change the dataUrl for next dropdown.
My code so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
$(function () { var lastsel2 $("#jqGrid_BdgtEmp").jqGrid({ regional: 'en', prmNames: { id: "empTbID" }, url: "/Budget/GetBdgtEmp", datatype: 'json', mtype: 'Get', colNames: ['EmpTbID', 'DepartmentId', 'DepartmentName', 'EmployeeName', 'EmployeeJobFunctionId', 'EmployeeJobFunctionName', 'EmpStart', 'EmpEnd', 'BsBasic', 'BsPayRise', 'BsComm', 'BsOverTime', 'BsMthBonus', 'BsQtrBonus', 'BsGross', 'RatesEmpNhi', 'RatesPension', 'BoEmpNhi', 'BoPension', 'BoHealth', 'BoBenefits', 'BoTotal', 'CarStatus', 'CarWDown', 'CarFuel', 'CarRunCost', 'CarTotal', 'PayRisePercent', 'PayRiseStart'], colModel: [ { key: true, name: 'empTbID', index: 'empTbID', editable: false, editoptions: { "class": "jqgrid-readonlycolumn" } }, { key: false, name: 'departmentId', index: 'departmentId', editable: true }, { key: false, name: 'departmentName', index: 'departmentName', editable: true, edittype: 'select', editoptions: { size: 1, dataUrl: '/Budget/GetDepartmentListSel' } }, { key: false, name: 'employeeName', index: 'employeeName', editable: true }, { key: false, name: 'employeeJobFunctionId', index: 'employeeJobFunctionId', editable: true }, { key: false, name: 'employeeJobFunctionName', index: 'employeeJobFunctionName', editable: true }, { key: false, name: 'empStart', index: 'empStart', editable: true }, { key: false, name: 'empEnd', index: 'empEnd', editable: true }, { key: false, name: 'bsBasic', index: 'bsBasic', editable: true }, { key: false, name: 'bsPayRise', index: 'bsPayRise', editable: true }, { key: false, name: 'bsComm', index: 'bsComm', editable: true }, { key: false, name: 'bsOverTime', index: 'bsOverTime', editable: true }, { key: false, name: 'bsMthBonus', index: 'bsMthBonus', editable: true }, { key: false, name: 'bsQtrBonus', index: 'bsQtrBonus', editable: true }, { key: false, name: 'bsGross', index: 'bsGross', editable: true }, { key: false, name: 'ratesEmpNhi', index: 'ratesEmpNhi', editable: true }, { key: false, name: 'ratesPension', index: 'ratesPension', editable: true }, { key: false, name: 'boEmpNhi', index: 'boEmpNhi', editable: true }, { key: false, name: 'boPension', index: 'boPension', editable: true }, { key: false, name: 'boHealth', index: 'boHealth', editable: true }, { key: false, name: 'boBenefits', index: 'boBenefits', editable: true }, { key: false, name: 'boTotal', index: 'boTotal', editable: true }, { key: false, name: 'carStatus', index: 'carStatus', editable: true }, { key: false, name: 'carWDown', index: 'carWDown', editable: true }, { key: false, name: 'carFuel', index: 'carFuel', editable: true }, { key: false, name: 'carRunCost', index: 'carRunCost', editable: true }, { key: false, name: 'carTotal', index: 'carTotal', editable: true }, { key: false, name: 'payRisePercent', index: 'payRisePercent', editable: true }, { key: false, name: 'payRiseStart', index: 'payRiseStart', editable: true }], onSelectRow: function (empTbID) { if (empTbID && empTbID !== lastsel2) { $("#jqGrid_BdgtEmp").restoreRow(lastsel2); $("#jqGrid_BdgtEmp").editRow(empTbID, true, '', '', '', '', reload); lastsel2 = empTbID; } }, footerrow: true, userDataOnFooter : true, editurl: '/Budget/EditBdgtEmp', pager: jQuery('#jqControlls_BdgtEmp'), rowNum: 10, rowList: [10, 20, 30, 40, 50], height: '100%', viewrecords: true, caption: 'Employees', emptyrecords: 'No employees to display', jsonReader: { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, Id: "0" }, autowidth: false, shrinkToFit:false, forceFit:false, multiselect: false, loadComplete: function () { // footer data $(this).jqGrid("footerData", "set", { empTbID: "<b>Total:</b>", bsBasic: $(this).jqGrid('getCol', 'bsBasic', false, 'sum'), bsPayRise: $(this).jqGrid('getCol', 'bsPayRise', false, 'sum'), bsComm: $(this).jqGrid('getCol', 'bsComm', false, 'sum') }); } }).navGrid('#jqControlls_BdgtEmp', { edit: true, add: true, del: true, search: false, refresh: true }, { zIndex: 100, url: '/Budget/EditBdgtEmp', closeOnEscape: true, closeAfterEdit: true, recreateForm: true, afterComplete: function (response) { if (response.responseText) { console.log(response.responseText); } } }, { zIndex: 100, url: "/Budget/CreateBdgtEmp", closeOnEscape: true, closeAfterAdd: true, afterComplete: function (response) { if (response.responseText) { console.log(response.responseText); } } }, { zIndex: 100, url: "/Budget/DeleteBdgtEmp", closeOnEscape: true, closeAfterDelete: true, recreateForm: true, msg: "Are you sure you want to delete this row? ", afterComplete: function (response) { if (response.responseText) { console.log(response.responseText); } } }); $("#jqGrid_BdgtEmp").jqGrid('setGroupHeaders', { useColSpanStyle: false, groupHeaders: [ { startColumnName: 'empTbID', numberOfColumns: 12, titleText: '<b>Top level placeholder</b>' } ] }); $("#jqGrid_BdgtEmp").jqGrid('setGroupHeaders', { useColSpanStyle: false, groupHeaders: [ { startColumnName: 'empTbID', numberOfColumns: 2, titleText: '<b>Mid placeholder 1</b>' }, { startColumnName: 'departmentName', numberOfColumns: 6, titleText: '<b>Mid placeholder 2</b>' } ] }); function reload(empTbID, result) { $("#jqGrid_BdgtEmp").trigger("reloadGrid"); } }); |
So in my example above, when user selects the department I need to then load a relevant list of Job Function descriptions based on that initial selection.
Hope you guys can help me – and code examples would be greatly appreciated!
Pawel
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top