Own Filter Layout

May 30, 2013 at 2:42 PM
Hi, I need my own filter fields layout. I'm trying this:

I'll made view with grid as form and I'm sending model to search viewmodel.

@model JobCustomSearchViewModel

@using (Html.BeginForm("Jobs", "Jobs", FormMethod.Post))
  ... my model binded fields ...

var grid = new Lib.Web.Mvc.JQuery.JqGrid.JqGridHelper<JobPlannerMVC4.Areas.Planner.ViewModels.JobViewModel>("jobs",
        url: Url.Action("Jobs", "Jobs", @Model),
        public ActionResult Jobs(JqGridRequest request, JobCustomSearchViewModel viewModel)
            return new JqGridJsonResult() { Data = response };
after hitting Filter button, I'm trying to refresh grid with updated model:
var newGridDataUrl = '@Url.Action("Jobs", "Jobs", Model)';
jQuery('#jobs').jqGrid('setGridParam', { url: newGridDataUrl }).trigger("reloadGrid");
It's seemed to work, but refresh function keep sending the initial model, without updated values. Do you know what causes the problem? any help will be much appreciated. thank you.
Jun 1, 2013 at 10:19 AM

I will be guessing that you are intercepting the Form submit action (the Filter buton) with JavaScript in order to prevent the regular post back, and in that JavaScript you are trying to refresh the grid (at least it should be like this). If that is the case then your approach to refreshing the grid is wrong. First of all you can add your Model to URL, but you should set it as jqGrid postData option (with setGridParam method). The second thing is that you can't use your server side Model variable because that is not updated in any way on client side. You need to serialize your form into object in JavaScript and set that object for postData option value.
Jun 1, 2013 at 11:31 AM
Form serialization solved it, thank you Tomas.