Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid: sending edit data

Tags:

jqgrid

I'm trying to use form editing on jqgrid. When the data is sent to the webserver, I want an extra field sent in the get/post data.

It sounds like editData is what I want to use. How do I hook this into the navbar?

<script type="text/javascript">
    $(document).ready(function(){ 
        if (jQuery('#ReferenceGrid').attr('role') == 'undefined' || jQuery('#ReferenceGrid').attr('role') == null) {
            var lastSel;
            jQuery('#ReferenceGrid').jqGrid({
                url: '/PlannedWorkOrder/Items/',
                datatype: 'json',
                postData: { referenceNumber: $('#reference').text() },
                colNames: ['Platinum Part Number', 'Quantity'],
                colModel: [
                    { name: 'PlatinumPartNumber', index: 'PlatinumPartNumber', width: 300, sortable: false, editable: true },
                    { name: 'Quantity', index: 'Quantity', width: 300, sortable: false, editable: true, editrules:{integer: true}  },
                ],
                jsonReader: {
                    cell: "",
                    id: "PlatinumPartNumber",
                    repeatitems: false
                },
                search:false,
                viewrecords: true,
                height: '100%',
                sortorder: 'desc',
                caption: 'Details',
                altRows: true,
                pager : '#gridpager',
                pgbuttons: false,
                pginput: false,
                pgtext: false,
                viewrecords: false,
                editurl: '/PlannedWorkOrder/Item/'
            })
            jQuery("#ReferenceGrid").navGrid('#gridpager', { add: true, edit: true, search: false });
        }
        else {
            $("#ReferenceGrid").setGridParam({ postData: { firstName: $('#Reference').val(), lastName: $('#Reference').val() } });
            $("#ReferenceGrid").trigger("reloadGrid")
        }
    });

</script>
like image 478
Adam Tegen Avatar asked Dec 28 '22 09:12

Adam Tegen


1 Answers

To add additional parameters which will be sent during adding/editing of data in form editing you can use editData:

jQuery('#ReferenceGrid').jqGrid('navGrid',"#gridpager",
    {},
    {editData: {firstName: $('#Reference').val(),
                lastName: $('#Reference').text()}}, // edit options
    {editData: {firstName: $('#Reference').val(),
                lastName: $('#Reference').text()}); // add options

Moreover your construction with jQuery('#ReferenceGrid').attr('role') looks a little strange. Probably you find the solution of the same problem in my old suggestion How to filter the jqGrid data NOT using the built in search/filter box. I recommend you to use postData as a function: use

postData: { referenceNumber: function() { return $('#reference').text(); } },

instead of

postData: { referenceNumber: $('#reference').text() },
like image 77
Oleg Avatar answered Jan 18 '23 17:01

Oleg