Home › Forums › Guriddo jqGrid JS › Help › Master Detail grid and inline editing
Tagged: editing, master detail
Hey guys
Im new to jqgrid and im trying to get an understanding of how it all holds together.
Basically i need to have 2 grids. In grid one i select a customer and then in grid 2 it will display all orders for that customer. However in grid 2 i want to be able to edit in line as well as add new lines.
First i was thinking master->detail grid but for some reason you cant edit lines in the detail grid? is that by design? or did i miss something
Hello,
The master-detail example you refer is just a demo. We can not put all the features in one example.
This is not by design and actually we have exactly the code you want, but with our PHP jqGrid component – here
The PHP component generate the same jqGrid’s.
If you have difficulties, please let us know where you have such one and which editing module you use.
Kind Regards,
Will
Guriddo Support Team
ok so just so that im clear. the back end for all the grid is just javascript? so that everything you are doing in that php example is possible in straight javascript? like the master->detail example?
Hello,
No. Most of operations like retrieving data, sorting, paging, searching are performed at PHP end. The build of grid is based and some descriptions of the php script and the script generates automatically the java script code.
For clarification in master grid we use onselectRow, onPaging, onSortCol events,
The javascript for onSelectRow is:
|
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 |
onSelectRow : function(rowid, selected) { if(rowid != null) { jQuery("#detail").jqGrid('setGridParam',{postData:{EmployeeID:rowid}}); jQuery("#detail").jqGrid('setColProp','EmployeeID',{editoptions:{defaultValue:rowid}}); jQuery("#detail").trigger("reloadGrid"); // Enable CRUD buttons in navigator when a row is selected jQuery("#add_detail").removeClass("ui-state-disabled"); jQuery("#edit_detail").removeClass("ui-state-disabled"); jQuery("#del_detail").removeClass("ui-state-disabled"); } }, onPaging : function(rowid, selected) { // clear the grid data and footer data jQuery("#detail").jqGrid('clearGridData',true); // Disable CRUD buttons in navigator when a row is not selected jQuery("#add_detail").addClass("ui-state-disabled"); jQuery("#edit_detail").addClass("ui-state-disabled"); jQuery("#del_detail").addClass("ui-state-disabled"); }, onSortCol : function(rowid, selected) { // clear the grid data and footer data jQuery("#detail").jqGrid('clearGridData',true); // Disable CRUD buttons in navigator when a row is not selected jQuery("#add_detail").addClass("ui-state-disabled"); jQuery("#edit_detail").addClass("ui-state-disabled"); jQuery("#del_detail").addClass("ui-state-disabled"); }, .... |
In the detail grid we use beforShowForm for adding and recreateForm : true for add and edit.
These options should be set in navigator add, edit events
The code for beforeShowForm is:
|
1 2 3 4 5 6 7 8 9 10 |
beforeShowForm : function(formid) { var srow = jQuery("#grid").jqGrid('getGridParam','selrow'); if(srow) { var gridrow = jQuery("#grid").jqGrid('getRowData',srow); $("#EmployeeID",formid).val(gridrow.EmployeeID); } } |
Kind Regards,
great thanks for that. It solved my problem.
I have two more questions.
Hello,
1.
If you know the id of your grid you can
|
1 2 3 |
<style> .ui-jqgrid #mygrid tr.jqgrow td {height:40px;} </style> |
2. We have a Knowledgebase. Look here
Kind Regards,
Tony thanks so much that helped me.
I have one final question.
when using inline editing you enter a value and then press enter. this then posts the data.
I can see in consol that the data is coming in. However i need to add a security token to the end of the post.
how would i do this. I have searched and tried a number of different methods but cant find one that works.
so currently it looks like
<span class=”header-value source-code”>client=200012&Order=1&oper=edit&id=1
i need
client=200012&Order=1&oper=edit&id=1&key=kjkzxlkjklj213kl2
</span>
Hello,
Use serializeRowData to send additional parameters when post the data to the server in inline edit.
See here
Kind Regards,
thanks for that. I have the serialize part working.
But i cant get the extra param in.
I have tried.
editParams: { extraparam: {csrf_token: function() {return $("meta[name=csrf_token]").attr("content");}}},
extraparam: {csrf_token: function() {return $("meta[name=csrf_token]").attr("content");}},
the below works. But i need the token inside the object
|
1 2 3 4 |
serializeRowData: function(postdata) { return { x01: JSON.stringify(postdata ) + $("meta[name=csrf_token]").attr("content")}; }, |
Tony
thanks so much for your help.
Everything has worked really well so far. I have 2 more questions. I have tried a few options but no results.
|
1 2 3 4 5 |
serializeRowData: function(postdata) { postdata["csrf_token"] = $("meta[name=csrf_token]").attr("content"); return postdata; }, |
2. I am using the popup search grid. However i want the search grid to display the name and return the id for the selected row. is this possible?
thanks so much for your help so far
Hello,
Thank you for the feedback.
It is a good idea to post the new questions in different post.
Kind Regards,
Thanks for that. Here is my code for the options. Im using inline editing and then the add and delete in the nav bar.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$('#jqGridDetails').navGrid('#jqGridDetailsPager', // the buttons to appear on the toolbar of the grid { edit: false, add: false, del: true, search: false, refresh: false, view: false, position: "left", cloneToTop: false }); $('#jqGridDetails').jqGrid('inlineNav', '#jqGridDetailsPager', {addParams: {position: "last"}, edit: false}); var lastSelection; function editRow(id) { if (id && id !== lastSelection) { var grid = $("#jqGridDetails"); grid.jqGrid('restoreRow',lastSelection); grid.jqGrid('editRow',id, {keys: true} ); lastSelection = id; }; }; |
But i cant seem to get it to add the serializeDelData that i have added to the grid.
maybe i am doing it wrong
Hello,
In navGrid when you set del:true you can set additional delete parameters. This is the 4 parameter object:
|
1 2 3 4 5 6 7 8 |
$('#jqGridDetails').navGrid('#jqGridDetailsPager', { edit: false, add: false, del: true, search: false, refresh: false, view: false, position: "left", cloneToTop: false }, {}, {}, { serializeDelData : function( postdata ) {...}}, ... ); ... |
Kind Regards,
Will
Guriddo Support Team
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top