robinvanderknaap / MvcJqGrid

Fluent jqGrid Html Helper for ASP.NET MVC
www.playground.webpirates.nl/mvcjqgrid
GNU Lesser General Public License v3.0
101 stars 74 forks source link

How can I rebind (refresh) the grid by change method from a DropDownList? #48

Closed jbengoa closed 9 years ago

jbengoa commented 10 years ago

How can I rebind (refresh) the grid by change method from a DropDownList?

I don't see a reloadGrid div for accesing it via jQuery or something like that, like the implementation in jqgrid original. Now I need to refresh the grid while changing a DropDownList with his ID to pass it to the controller.

Somebody?

robinvanderknaap commented 10 years ago

When you declare the grid like this: @(Html.Grid("nameOfYourGrid")....

The following code triggers the reload: $('#nameOfYourGrid').trigger( 'reloadGrid' );

You should be able to bind the change event to this code.

jbengoa commented 10 years ago

I'm doing this:

$(function () {
    $('#IdFormulario').change(function () {
        Search($('#IdFormulario option:selected').val());
    });
});

Search = function (id) {
    $.getJSON('@Url.Action("Search", "encuestas")', { _idFormulario: id }, function (data) {
        $("#gEncuesta").setGridParam({ 'data': data }).trigger("reloadGrid");
    });
}

But... it doesn't refresh correctly the grid.

In the Chrome console I got this JSON:

{"total":1,"page":1,"records":1,"rows":[{"IdEncuesta":1,"NumSol":"2585","CodEvaluador":"2007022","CodEvaluado":"2007024","Fecha":"01-08-2014","Observaciones":"N/D","Puntuacion":31}]}