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

NodeJS/Express rendering Kendo Grid with EJS: grid function doesn't work

2 Answers 332 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ilya
Top achievements
Rank 1
Ilya asked on 05 Nov 2014, 08:25 AM
Hi,

All code below runs on NodeJS/Express/EJS.
I have a two file form.js and grid.js.

In the form.js I create grid object and define custom validator like here:
-------------------------------------------------------------------------------------------------
...
rest.get(uri, {}).on('complete', function (data, result) {
         var schemeGridColumns = {};
         ...
         schemeGridColumns["field1"].validation = {
                                                                          required: true,
                                                                          custom: function (input) {
                                                                                  if (input.is("[name=field1]") && input.val().length > 5)  {
                                                                                          input.attr("data-custom-msg", "My notification from validator.");
                                                                                          return false;
                                                                                   }
                                                                                   return true;
                                                                    }
       ...
       var grid = {
              editable: {
                    mode: "popup",
                    ....
              },
             transport: {
             ..... 
             },
             ...
            dataSource: {
                   ....
                   schema: {
                          data: 'data',
                          total: 'total',
                          model: {
                               id: gridKeys,
                               fields: gridSchemaFields
                          }
                   }
            },
           ....
      };

      res.render("grid.js", grid: grid, ....);
)};
--------------------------------------------------------------------------
File grid.js looks like this:
----------------------------------------------------------------------------
<div id="grid" style1="float:left"></div>
<div class="clear1"></div>

<script language="javascript">
    $(document).ready(function() {
        titan.setTitle('<%= title %>');

        // create Kendo UI Grid
        $('#grid').kendoGrid(<%- JSON.stringify(grid) %>);

    });
</script>
--------------------------------------------------------------------------------
The problem is that standard validation require works in popup,
but custom doesn't fire. I've tried with inline mode. Result is the same.
May be problem with EJS template compiler?






2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 07 Nov 2014, 07:58 AM
Hello Ilya,

We are not sure what exactly is wrong, however I can see that you are stringifying the object before passing it to the Grid, are you sure that function are actually serialized and then outputed? Could you check the source code of the page that was rendered (ctrl + U in the browser) and see if the validation is actually there.

Let us know your findings.

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
Ilya
Top achievements
Rank 1
answered on 07 Nov 2014, 11:17 AM
Hi Petur,

yes, you're right. I already found it in JSONstringify documentation. I reorganized code to avoid this function.
Thanks that you confirm my suggestion! 
Tags
Grid
Asked by
Ilya
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Ilya
Top achievements
Rank 1
Share this question
or