Home › Forums › Guriddo jqGrid JS › Inline edit with only select boxes
Hey guys
I am using a grid with only select and check boxes.
However i can add a new row and delete a row.
But when i edit the user has to press enter to fire save. this wont work as they might forget and leave the grid which will reset all their changes.
Is there a way to call the save function after they change any field in the row?
Hello,
Which editing module is used? One small code example will be fine.
You can bind a change event to the field and post the data to the server when it is changed.
For this purpose you can use dataInit event – but without any additional information we can not help.
Kind Regards
Will
Guriddo Support Team
|
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 |
function loadapprovalsgrid(approvallist) { $("#Approvals_grid").jqGrid({ url: site['uri']['public'] + '/data/Config/Approvals/empid', editurl: site['uri']['public'] + '/data/Config/Approvals/', datatype: "json", colModel: [ { label: 'ID', name: 'id', key: true, width: 10, hidden: true }, { label: 'application', name: 'application', width: 40,editable: true, formatter: 'select', edittype:'select',editoptions:{value:"timesheets:timesheets;expenses:expenses"}}, { label: 'group', name: 'group_id', width: 150 ,editable: true,formatter:'select', edittype:'select', editoptions: {value: approvallist }},// "1:'test1';2:'test2'" { label: 'employee_id', name: 'employee_id', width: 20, hidden: true }, { label: 'edit', name: 'can_edit', width: 25, editable: true,formatter:'checkbox', edittype:'checkbox', editoptions: { value:"Y:N" }}, { label: 'approve', name: 'can_approve', width: 25, editable: true,formatter:'checkbox', edittype:'checkbox', editoptions: { value:"Y:N" }} ], width: '500', rowNum: 200, keys: true, onSelectRow: editRowApprovals, pgtext : "", pgbuttons: false, height: '100', viewrecords: true, caption: 'Approvals', serializeRowData: function(postdata) { postdata["csrf_token"] = $("meta[name=csrf_token]").attr("content"); postdata["employee_id"] = employee_id; return postdata; }, pager: "#Approvals_gridPager" }); $('#Approvals_grid').navGrid('#Approvals_gridPager', { edit: false, add: false, del: true, search: false, refresh: false, view: false, position: "left", cloneToTop: false }, {}, {}, { serializeDelData : function( postdata ) { postdata["csrf_token"] = $("meta[name=csrf_token]").attr("content"); return postdata; } } ); $('#Approvals_grid').jqGrid('inlineNav', '#Approvals_gridPager', {addParams: {position: "last",addRowParams: {successfunc: updateApprovals} , edit: false}}); var lastSelectionApprovals; function updateApprovals(response) { jQuery("#Approvals_grid").jqGrid('setGridParam',{url: site['uri']['public'] + '/data/Config/Approvals/'+employee_id}); jQuery("#Approvals_grid").trigger("reloadGrid"); } function editRowApprovals(id) { if (id && id !== lastSelectionApprovals) { var grid = $("#Approvals_grid"); grid.jqGrid('restoreRow',lastSelectionApprovals); grid.jqGrid('editRow',id, {keys: true} ); lastSelectionApprovals = id; }; }; } |
above is the code for the grid i made.
So there is no way i can just call saverow and force the grid to save using the edit url? and a change event doesnt seem to work i did give that a try
Hello,
dataInit works for us. Here is a solution, which I think is not the best one, but it works. It is applied for one field, but you can do it for all the editable one:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
function loadapprovalsgrid(approvallist) { $("#Approvals_grid").jqGrid({ url: site['uri']['public'] + '/data/Config/Approvals/empid', editurl: site['uri']['public'] + '/data/Config/Approvals/', datatype: "json", colModel: [ { label: 'ID', name: 'id', key: true, width: 10, hidden: true }, { label: 'application', name: 'application', width: 40,editable: true, formatter: 'select', edittype:'select',editoptions:{value:"timesheets:timesheets;expenses:expenses", dataInit : function(el){ $(el).on('change', function(e){ $('#grid').jqGrid('saveRow',lastSelectionApprovals); $('#grid').jqGrid('editRow',lastSelectionApprovals, {keys: true}); }); }}, .... } |
Hope you have got the point.
Kind Regards,
Will
Guriddo Support Team
great. I wasnt sure if i could call save and edit row one after the other. But it works and gives me the result i wanted
Hello,
Thank you for the feedback.
Kind Regards,
Will
Guriddo Support Team
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top