Edit this page

Transform Invalid Data Item Keys into Valid Ones

Sometimes the received remote data contains fields that are not valid JavaScript identifiers.

To manipulate the received data and transform it so that it can be processed by the DataSource, use the schema.parse() method to replace the non-supported keys with supported.

The following example demonstrates how to use the schema.parse() method to transform invalid data item keys into valid ones.

Example
    <div id="grid"></div>
    <script>
          $(document).ready(function () {
              var d = [{id: 1,
                  "As Of Date": new Date("01/01/1991")
              }, {id:2,
                  "As Of Date": new Date("01/01/1990")
              }];

              $("#grid").kendoGrid({
                  editable: "popup",
                  dataSource: {
                      transport: {
                          read: function (e) {
                              // on success
                              e.success(d);
                              // on failure
                              //e.error("XHR response", "status code", "error message");
                          },
                          update: function (e) {
                              // persist the new data
                              d = e.data;

                              e.success();
                          }
                      },
                      schema: {
                          parse: function (response) {
                              // transform the objects so that they do not contain "illegal" identifiers
                              response.forEach(function (item) {
                                  item.field1 = item["As Of Date"];
                                  delete item['As Of Date'];
                              });

                              return response;
                          },
                          model: {
                              fields: {
                                  "id": "id",
                                  "field1": {
                                      type: "date",
                                  }
                              }
                          }
                      }
                  },
                  columns: [
                    {
                        command: [{ name: "edit" }]
                    },
                          { field: "field1", format: "{0:MM/dd/yyyy}", title: "As Of Date" }
                  ]
              });
          });
      </script>

See Also

For more runnable examples on the Kendo UI Grid, browse its How To documentation folder.

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy