I have an existing project that I need to maintain, but this is first time I meet the jqGrid...
Mainly, I have a Product
, that can have multiple Formule
s. Each Formule
can contain multiple Period
s. A Period
is described by a DepartureDate
and a Price
.
This is the code that manages the Period's grid. Specially it adds the grid's navigator with the posibility of add Period
s.
When adding a new row in the grid, the user fills-up a form containing 2 fiels: the DepartureDate and a Price corresponding to the newly created Period.
jQuery("#periode-grid").jqGrid(
'setGridParam',
{
postData: {
formuleId: rowid // <<< !!!
},
datatype: "json"
})
.navGrid("#periode-pager",
{
"edit": false, "add": true, "del": false,
"search": true, "addtext": "@Resources.Main.Grid_Add"
},
{},
{
"url": '@Url.Action("AddAjaxPeriod",
new { elementId = @ViewData["ProductId"] })', // <<< !!!
"closeOnEscape": true, "closeAfterAdd": true,
"reloadAfterSubmit": true, "width": 500,
"beforeSubmit": BeforeFormuleSubmit
});
And this is my AddAjaxPeriod
signature, containing 4 parameters, including the date and price:
[HttpPost]
[AjaxRequestOnly]
[Transaction]
public JsonResult AddAjaxPeriod(Guid elementId, Guid formuleId,
DateTime departureDate, double price)
{ ... }
Now everything works fine untill I open the form to add the price and date, fill-in the requested date and price, and click Validate.
I obtain an Error saying that AddAjaxPeriod
requests departureDate
non-optional parameter and is not filled-in... I could agree, I fill-in the elementId
via the anonymous method, the formuleId
is set in the postData
, but the departureData
and price
are in the form the the user tries to add. Is there a way to get the values of that "add form" (date and price) and pass them into the AddAjaxPeriod
method?
EDIT:
After the Oleg remarks, I found the grid initialization (in occurence in an parent partial view). This is the code:
jQuery("#periode-grid").jqGrid({
"url": '@Url.Action("PeriodePagedList", new { elementId = ViewData["ProductId"] })',
"datatype": 'local',
"mtype": 'POST',
"width": 400,
"height": 100,
"colNames": [
"@Resources.Catalog_Products.FormulePeriode_DepartureDate",
"@Resources.Catalog_Products.FormulePeriode_Price",
"" // Actions
],
"colModel": [
{ "name": 'DepartureDate', "index": 'DepartureDate', "editable": true, "align": 'center', "width": 100, "sorttype": 'date', "datefmt": 'dd/mm/yyyy', "editoptions": { "dataInit": function (element) { jQuery(element).datepicker({ "dateFormat": 'dd/mm/yy', "minDate": 0, "showAnim": '' }) } }, "editrules": { "required": true, "date": true } },
{ "name": 'Price', "index": 'Price', "editable": true, "align": 'center', "editrules": { "required": true }, "width": 100, "formatter": currencyFormatter, "unformat": unformatCurrency },
{ "name": 'Actions', "index": 'Actions', "width": 50, "align": 'center', "search": false, "sortable": false }
],
"sortname": 'DepartureDate',
"rowNum": 100,
"loadComplete": OnLoadPeriodeComplete,
"pager": jQuery('#periode-pager'),
"pginput": false,
"pgbuttons": false,
"viewrecords": false,
"imgpath": '@Url.Content("~/Content/jqueryui/images")',
"caption": "@Resources.Catalog_Products.FormulePeriode_GridTitle",
"shrinkToFit": true,
"hidegrid": false
});