0

I have got an asp.net form, with a jqgrid on it. The user can enter an account number on a main form, and then enter some data onto a jqgrid.

At the point the user saves the row in the grid, i would also like to pass the account number across from the form to the save proc, as we use this to work out some discount info for the lines in the grid.

I'm not sure how at the point of saving to pass this information accross?

UPDATE

I'm using json as my datatype, using inline editing and using editurl to post the grid to a web service that deals with saving it to a back end database.

UPDATE 2 - Solution

This is the code i have used to pass the value of a text box to along with the normal post data

jQuery(grid).jqGrid('inlineNav', "#pager", { edit: false, add: true, del: false, search: false,

                //add the extra params to the post call
                addParams: {
                    useDefValues: true,
                    addRowParams: {
                        keys: true,
                        aftersavefunc: reloadGrid,
                        extraparam: { accNo: getAccNumber, colourName: getColName }
                    }
                },
                editParams: {
                    keys: true,
                    aftersavefunc: reloadGrid,
                    extraparam: { accNo: getAccNumber, colourName: getColName }
                }
            });

This function gets the value of the asp.net text box

//get the value of the account number field
            getAccNumber = function () {
                return $("#<%= txtAccNo.ClientID %>").val();
            };
beakersoft
  • 2,316
  • 6
  • 30
  • 40
  • You should post more about your implementation. For example: which `datatype` you use in the grid? Which editing mode of jqGrid you use? Do you save the data in the grid locally or on the server (is `editurl: 'clientArray'`, `cellsubmit: 'clientArray'` or some other local editing)? – Oleg Oct 23 '12 at 15:12
  • Oleg, added more info to the question – beakersoft Oct 23 '12 at 15:52

1 Answers1

0

You can use extraparam option of editRow:

onSelectRow: function (id) {
    ...
    $(this).jqGrid('editRow', id, {
        keys: true,
        url: "yourServerUrl",
        extraparam: {
            accountNumber: function () {
                return $("#accountNr").val();
            }
        }
    });
    ....
}

Additional parameter accountNumber with the current value from the input field with id="accountNr" will be sent additionally to the standard data.

You can see here the corresponding demo. Because no URL are exist under http://www.ok-soft-gmbh.com/jqGrid/myServerUrl one will get an error, but one can easy verify in the Fiddler, Firebug or in Developer Tools of IE or Chrome that additional parameter accountNumber will be really send to the server.

In case of ASP.NET code you could be needed to use the syntax like "<%=accountNumber.ClientID%>" to get id of the corresponding input field of the form.

One can use alternatively inlineData option of jqGrid with properties defined as methods. The idea here is the same as described here for postData. In the answer you will find an example where inlineData are used.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Im letting the user fill in the info on the grid, and they are saving it via the save icon on the pager. How will i add the data in is event, i'm asuming this demo is if you are saving everytime you alter a cell? Thanks – beakersoft Oct 25 '12 at 12:00
  • @beakersoft: It would be better if you post the code which you use. I am not sure that you correctly describes what you do. Do you use [inlineNav](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#inlinenav)? The problem is that the solution of the problem which you asked depend on many aspects of your current implementation. So without posting the JavaScript code we can just spent our time. – Oleg Oct 25 '12 at 15:41
  • i've got this working using the extraparam, putting it into the inlineNav. I'll post the code in my question – beakersoft Oct 26 '12 at 08:14
  • @beakersoft: You don't wrote in the question that you used `inlineNav`. There are **many different ways to use inline editing**: calling `editRow` directly, usage of `formatter: "actions"`, usage of `inlineNav`. In many cases the solution is quite different in all of above cases. So you should always exactly specify which way you have chosen or just post the code. I was not sure *which one* method you used. So I wrote you in the last part of my answer about `inlineData`. The way works **in all kind of usage of inline editing**. – Oleg Oct 26 '12 at 08:21