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

Change grid dataSource and send object as a parameter

4 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 30 Jan 2014, 05:14 PM
I am changing the url of a grid and then sending an object as a parameter. The grid is calling the new controller I want, but the view model is empty. What am I missing?

1.return mvvm.toJSON(self, function (data) {
2.                data.Criteria = self._grid.dataSource.data();
3.            });

New grid datasource:
01.var dataSource = new kendo.data.DataSource({
02.     page: ds.page(),
03.     pageSize: ds.pageSize(),
04.     sort: ds.sort(),
05.     type: "aspnetmvc-ajax",
06.     transport: {
07.          prefix:"",
08.          read:  {
09.          url: "/AdvancedSearch/GetResults",
10.          dataType: "json",
11.          data: { criteria: data },
12.          type: "POST",
13.          traditional: true,
14.          contentType: "application/json",
15.       }
16.   }
17.});

Replacing grid datasource:
1.self.bindings.controls.EquipmentListGrid.setDataSource(dataSource);
2.self.bindings.controls.EquipmentListGrid.rebind();

Controller:
1.[HttpPost]
2.public ActionResult GetResults([DataSourceRequest] DataSourceRequest request, AdvancedSearchViewModel criteria)
3.{
4.}

ViewModel:
01.[Serializable]
02.public class AdvancedSearchViewModel
03. {
04.        [DisplayName("Include Junk Pool")]
05.        public bool IncludeJunkPool { get; set; }
06.        public List<string> Areas { get; set; }
07.        public List<string> GeoMarkets { get; set; }
08.        public bool ApplyBasket { get; set; }
09.        public IList<int> Basket { get; set; }
10.        public bool Export { get { return true; } }
11. 
12.        public string Page { get; set; }
13.        public string Column { get; set; }
14.        public string DisplayName { get; set; }
15.        public string Operator { get; set; }
16.        public string Value { get; set; }
17.        public string DataType { get; set; }
18.        public string Table { get; set; }
19. 
20.        public IList<AdvancedSearchListItem> Criteria { get; set; }
21. 
22.        public CurrentPage CurrentPage { get; set; }
23.        public Sort Sort { get; set; }
24.}

1.return mvvm.toJSON(self, function (data) {
2.     data.Criteria = self._grid.dataSource.data();
3.});

1.return mvvm.toJSON(self, function (data) {
2.     data.Criteria = self._grid.dataSource.data();
3.});

4 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 03 Feb 2014, 12:13 PM
Hello Alex,

We are not sure what exactly is causing the issue. Could you share with us how does the request look like when inspected from the network tab of your browser (F12 tools).

Also are you able to send the viewmodel by using regular $.ajax instead of the dataSource object?

In order to advise you please send us a small sample project that demonstrate the case.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alex
Top achievements
Rank 1
answered on 04 Feb 2014, 08:22 PM
I was able to send the view model as a function within grid read. But the DataSourceRequest is now null. None of the paging info is being passed to the controller.

advancedsearch.show({
                page: 'EquipmentSearch',
                area: '',
                controller: 'AdvancedSearch',
                action: 'GetView',
                title: 'Equipment',
                success: function (viewModel) {
                    var dataSource = new kendo.data.DataSource({
                        sort: [],
                        serverPaging: true,
                        serverFiltering: true,
                        serverGrouping: true,
                        serverSorting: true,
                        serverAggregates: true,
                        transport: {
                            prefix: "",
                            read: function (options) {
                                rite.json({
                                    action: 'GetResults',
                                    controller: 'AdvancedSearch',
                                    area: '',
                                    data: { criteria: viewModel },
                                    success: function (response) {
                                        options.success(response);
                                    }
                                });
                            }
                        },
                        schema: {
                            total: function (response) {
                                return response.Total;
                            },
                            data: function (response) {
                                return response.Data;
                            },
                            errors: function (response) {
                                return response.Errors;
                            },
                            aggregates: function (response) {
                                return response.AggegateResults;
                            }
                        }
                    });

                    self.grid.setDataSource(dataSource);
                    self.grid.rebind();
                }
            });

This is the request (F12)


Preview of response
0
Alex
Top achievements
Rank 1
answered on 04 Feb 2014, 08:24 PM
Attached pics
0
Petur Subev
Telerik team
answered on 06 Feb 2014, 01:53 PM
Hello again,

What is that rite object that you use to perform posting?

transport: {
                            prefix: "",
                            read: function (options) {
                                rite.json({

Did you try to set the contentType to be application/json ?

Send a project which we can run to investigate further.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Alex
Top achievements
Rank 1
Share this question
or