Forum
Edit: I feel mildly for not mentioning that I am using MVC and visual basic. I can convert c# fairly good though so whatever works.
Hi, I am rather new to javascript, jquery and of course jqgrid.
I have several problems at the moment and would appreciate some help if at all possible.
1. I need to "POST" dataUrl + row_id on edit of a selected row using modal dialog.
2. I need to return data such that all Roles are returned and items are selected based on the User / Roles relationship.
So far I have been able to figure everything out myself with the help of Google… but this is giving me a fit.
Here is my jqGrid code. (sorry I couldn't figure out a good way to post the code!)
//to add datepicker to column search/edit/add //searchoptions: {sopt: ['cn'], dataInit: function(el) { $(el).datepicker({ dateFormat: 'mm-dd-yy' }); } } jQuery(document).ready(function() { jQuery("#MyDynamicGrid2").jqGrid({ url: '/User/UserGridData/', mtype: 'POST', datatype: 'json', colModel: [ { name: 'EmpName', index: 'EmpName', width: 80, align: 'left', editable: true, resizable: true, searchoptions: { sopt: ['cn']} }, { name: 'UserName', index: 'UserName', width: 80, align: 'center', editable: true, resizable: true, searchoptions: { sopt: ['cn']}}, { name: 'Roles', index: 'Roles', width: 80, align: 'center', editable: true, resizable: true, searchoptions: { sopt: ['cn']}, edittype:"select",editoptions: {dataUrl: '/User/UserGridRoles/', multiple:true, edittype: 'select'}, editrules:{required:true}}, { name: 'Department', index: 'DepartmentName', width: 80, align: 'center', editable: true, resizable: true, searchoptions: { sopt: ['cn']}, edittype:"select", editoptions: { dataUrl: '/User/UserGridRoles/?id=' + $("#MyDynamicGrid2").jqGrid('getGridParam', 'selrow'), multiple:true, edittype: 'select', formatter: 'select' }, editrules:{required:true} }, { name: 'LastActivityDate', index: 'LastActivityDate', width: 80, align: 'center', editable: false, search: false, resizable: true, editrules: { edithidden: true } }, { name: 'UserId', index: 'UserId', width: 80, align: 'left', editable: false, resizable: true, key: true, hidden: true, editrules: { edithidden: true} }], colNames: ['EmpName', 'UserName', 'Roles', 'Department', 'LastActivityDate', 'UserId'], pager: jQuery('#pager2'), rowNum: 20, rowList: [10, 20, 30, 50], sortname: 'EmpName', sortorder: 'Asc', viewrecords: true, imgpath: '/Content/JqGridThemes/steel/images', caption: 'Users', //editurl: '/Reports/DynamicGridDataEdit/', height: 320, width: 900, viewsortcols: true, jsonReader: { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, userdata: "userdata" } }); jQuery("#MyDynamicGrid2").jqGrid('navGrid', '#pager2', { edit: true, edittext: 'Edit', add: true, addtext: 'Add', del: true, deltext: 'Delete', search: false, refresh: true }, { width: 350, url: '/User/UserGridDataEdit/', closeAfterEdit: 'true', modal: true }, // edit options {top: 50, left: "100", width: 500, url: '/User/UserGridDataAdd/', closeAfterAdd: 'true' }, // add options {url: '/User/UserGridDataDelete/', closeAfterAdd: 'true' }, //del options {multipleSearch: true} // search options ); jQuery("#MyDynamicGrid2").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, autosearch: true }); jQuery("#MyDynamicGrid2").jqGrid('navButtonAdd', '#pager2', { caption: "Export to Excel", onClickButton: function() { jQuery("#MyDynamicGrid2").excelExport(); } }); });
I found some info on stackoverflow from Olef.
I cannot get this suggestion to work, but I do think it is the right track. Sorry about the code here... I can't seem to figure out how to properly post code in this forum.
editoptions: { dataUrl: '/User/UserGridRoles/', buildSelect: function(data) { var response = jQuery.parseJSON(data.responseText); var s = '"; } , multiple:true, edittype: 'select' },
Well I sort of got it working… the only thing is that I cannot know which values to set selected (based on the Users Roles).
Now the values for the users roles show as comma separated in the grid originally prior to edit.
Where, or how can I tap into this data? If you see below I would be able to set selected for items
that were originally in the grid.
**Can someone help me post code properly to the forum?
{ name: 'Roles', index: 'Roles', width: 80, align: 'center', editable: true, resizable: true,
searchoptions: { sopt: ['cn'] }, edittype: 'select', editoptions: { multiple: true, edittype: 'select', dataUrl: '/User/UserGridRolesJson/', buildSelect: function(data) { data = jQuery.parseJSON(data); var sa = '" } } },
Most Users Ever Online: 715
Currently Online:
15 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66