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

grid selection - model/row

5 Answers 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Piyush Bhatt
Top achievements
Rank 2
Piyush Bhatt asked on 25 Dec 2011, 05:27 AM
This is mix of datasource/grid question. 

I have a [search] box with some criteria where user can enter some values and search, results gets displayed in grid and then I want to select the row. I am trying to get the [object] relevant to that row.

In following code, everything works upto selecting a row. I am not using the 'datasource' specification but instead using it within the search-click method. but how should I specify the schema/mode/id here so that when I select the row I can get row.data("id") value? As per following code, row.data("id") value is null.

Also, .data() method allows to store any object at the element level then why dont you store the whole object for the whole row.data()? and why you store only id? 

                $("#btnSearch").click(function() {
                    var searchobj = $("#searchForm").toDeepJson();
                    //console.log(searchobj);
                    myajax.WebService.SearchCustomers(searchobj, function(result) {
                        console.log(result.d);
                        gridCustomers.dataSource = new kendo.data.DataSource({
                            data: result.d,
                            schema: {
                                    model: { id: "Name" }
                            }
                        });
                        gridCustomers.dataSource.read();
                        gridCustomers.refresh();
                    }); //searchcustomers
                }); //btnSearch.click
            });                              //doc-ready


            function onChange(arg) {
                var row = this.select();
                var id = row.data("id");
                console.log(id);
            }

5 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 27 Dec 2011, 01:37 PM
Hello Piyush,

Generally speaking I do not see why you need to recreate Grid DataSource every time you change the filter criteria. The following jsFiddle demonstrates how you can achieve similar behavior by using DataSource filtering capabilities.

http://jsfiddle.net/rusev/ZpCAy/3/

To have id generated for the item you need to define schema/model/id. Then you can retrieve the Model for the item from the DataSource and access all it's properties via get method.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
BSV
Top achievements
Rank 1
answered on 29 Dec 2011, 01:31 PM
Hello

I have a similair problem as Piyush, and I've taken a look at the example. However, I don't wat to use the filter of the datasource, but rather want to use a json call to a server to do the filter for me.

Filtering on the datasource is not possible since the filtering is not straight forward (that is just a string matching) and requires a SQL server.

How can I reload the datasource ?

Kind regards Martijn
0
RMC
Top achievements
Rank 1
answered on 24 Jan 2012, 08:51 PM
$("#grid").data("kendoGrid").dataSource.filter({});
0
Nikolay Rusev
Telerik team
answered on 25 Jan 2012, 09:37 AM
Hello Martijn,

To refresh the data in DataSource you must filter it. 

"Filtering on the datasource is not possible since the filtering is not straight forward (that is just a string matching) and requires a SQL server."

I don't understand what do you mean. Can you explain?

Filtering in the case of the example in my previous post is performed on SQL server which is used by the service.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
RMC
Top achievements
Rank 1
answered on 25 Jan 2012, 04:31 PM
I posted  $("#grid").data("kendoGrid").dataSource.filter({});  because I use JSON data instead of  'odada', I had to implement the filter logic in the server side, calling ...filter({}) without filter conditions refresh the Data Source and get back all records
Tags
Grid
Asked by
Piyush Bhatt
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
BSV
Top achievements
Rank 1
RMC
Top achievements
Rank 1
Share this question
or