This is a migrated thread and some comments may be shown as answers.

Passing parameters back to the server so that a READ will get an altered data set

2 Answers 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lee Saunders
Top achievements
Rank 1
Lee Saunders asked on 21 Feb 2014, 09:41 PM
For example - a grid 
    @(Html.Kendo().Grid<CustomerModel>()
          .Name("ExampleGrid")
          .Pageable()
          .Sortable()
          .Groupable()
          .Resizable(resize => resize.Columns(true))
          .Reorderable(reorder => reorder.Columns(true))
          .Columns(columns =>
              {
                  columns.Bound(c => c.Name);
                  columns.Bound(c => c.System).Width(190);
                  columns.Bound(c => c.Principal).Width(190);
              })
          .DataSource(s => s
              .Ajax().Read(r => r.Action("GetContacts", "Example"))
              .PageSize(15))
          )   

is filled with data and then you want to - from the client JS - call READ so that the data is refreshed, but you want to send some parameters to the controller.

I've searched the web and and the best I can find is:
        var $grid = $("#ExampleGrid").data("kendoGrid");
        $grid.dataSource.read.data = viewModel;
        $grid.dataSource.read();

but, even though data is set to the correct object, the object is never sent to the server (confirmed by IE F12 Developer tools Network sniffer)

So, how do you send data back to the server when you tell the grid to read?

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 25 Feb 2014, 07:13 AM
Hello Lee,

DataSource.read method accepts as option additional data to send to server together with the current state. For example $grid.dataSource.read({ foo: "bar" }); will send to server the additional object with key `foo` and value `bar`.

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Lee Saunders
Top achievements
Rank 1
answered on 25 Feb 2014, 02:51 PM
Yep, that was it - I was mixing MVVM and the grid and ... well, they do not play well together in this specific instance.  The background JQuery blows up and I "ASSUMED" that it meant that passing data in the READ did not work. 

Turns our the READ needs a pure JS object, not an observable.

And I just learned that the .toJSON() off of an observable turns it back into a pure JS object.
Tags
Grid
Asked by
Lee Saunders
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Lee Saunders
Top achievements
Rank 1
Share this question
or