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

How to access kendoGrid data in parameterMap function

3 Answers 703 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Krishna
Top achievements
Rank 1
Krishna asked on 29 May 2013, 09:08 PM
I am using Kendo dataSource with transport (read, update, create) functionality. read operation retrieves data and displays it in a Grid. Gird has 3 columns - key, value, and class. Update operation edits a particular row taking in the options object as shown - 

 parameterMap : function (options, operation) {
      if (operation == "update") {
            return {key : options.models[0].key, value : options.models[0].value, class : options.models[0].class}
       }
}
The options object above is pre-loaded with the data in the particular row of the grid being edited.

However, for create operation, the options object is pre-set to null for all the fields. Options object is loaded when the user enters values for key and value. The value of class remains the same for all the rows, existing and new. How can I access the grid data (for the value of class) within the the code below?

 parameterMap : function (options, operation) {
      if (operation == "update") {
            return {key : options.models[0].key, value : options.models[0].value, class : options.models[0].class}
       }
     
      if (operation == "create") {
            return {key : options.models[0].key, value : options.models[0].value, class : <what code should go here?>}
       }
}

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 31 May 2013, 12:31 PM
Hello Krishna,

Whats is so special about that class field, and what is the problem to retrieve it the same way?
i.e.

{ class : options.models[0].class}

On a side note to specify default values you can use the model configuration of the dataSource.

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
Krishna
Top achievements
Rank 1
answered on 31 May 2013, 02:07 PM
Hi Petur,

What is special about the class field is that it is constant through out the grid (for all the records in the grid). The user is not privy to this field. So when it comes to 'create', all the fields within model are set to null. I need to access this field from the grid and pass it. The user will not be entering value for this field. Hence this field is not displayed in the create and update popups. This field is available as part of the grid, just that I am not displaying it on the screen anywhere. Here is a part of my code -

$("#defaultDetails").kendoGrid( {
                          dataSource : dataSource, pageable : true, selectable : 'row', sortable : true, filterable : false, reorderable : true, scrollable : false, 
                          toolbar : [{name : "create", text : "Add Record"}], 
                          columns : [
                            {field : "key", title : "Key", width : "100px"},
                            {field : "value", title : "Value", width : "100px"},
                            {command : ["edit"], title : " ", width : "60px"},
                            {command :  {name : "Remove", text : "Remove", className : "btn-destroy", click : deleteRecord},title : " ", width : "80px"},
                          ], 
                          editable :  {
                              mode : "popup", template : kendo.template($("#popup_editor").html())
                          }
                      });




If i were to add the below line to the above code, it will display the value of class. But it would display it only in the Update (edit) window, but not in the create window.

{field : "class", title : "Class", width : "100px"},

Hope this clarifies.
0
Petur Subev
Telerik team
answered on 04 Jun 2013, 12:50 PM
Hello Krishna,

If I understand you correctly you have this problem only in Internet Explorer? I assume you should not have such problem inside the Chrome browser, is that right?

What I tried to reproduce with the class keyword could be tested here:

http://jsbin.com/eleluv/2/edit

Is this the case? If yes you might consider parsing the object and changing that field name to another which is valid identifier in the JavaScript world. If not please create some sort of an example with the JSBin so we can check it and provide a solution.

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
Krishna
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Krishna
Top achievements
Rank 1
Share this question
or