1

I've got a Kendo grid and I'm trying to test a javascript function call after selecting a row.

<div id="datagrid">
    @(Html.Kendo().Grid(Model)
        .Name("datagrid_Concessoes")
        .Columns(columns =>
        {
            columns.Bound(c => c.Id).Width(70);
            columns.Bound(c => c.Code).Title("Código");
            columns.Bound(c => c.Description).Title("Descrição");
            columns.Bound(c => c.CreationDate).Title("Data de Criação");
            columns.Bound(c => c.CreationUser).Title("Criado por");
        })
        .HtmlAttributes(new { style = "height: 534px;" })
        .Scrollable()
        .Sortable()
        .Selectable()
        .Events(e => e.Change("test"))
        .Pageable(pageable => pageable
            .Refresh(true)
            .ButtonCount(5))
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(15)
            .Read(read => read.Action("GetConcessoes", "MasterData"))
        )
     )
</div>

and the javascript:

function test() {
    alert("test");
}

I get a javascript runtime error: 'test' is undefined as soon as the grid is about to be displayed. I tried the lines:

.Events(e => e.Change("test"))
.Events(e => e.Change("test()"))

but without luck

8
  • Which version of kendo ui and jqeury are you using ? Commented Jul 8, 2014 at 12:01
  • Could you try placing the function immediately before the grid & see what happens? It could just be that the function isn't defined yet Commented Jul 8, 2014 at 13:22
  • @mo.esmp, kendoUi version is the latest and jquery is 1.7.1 Commented Jul 8, 2014 at 13:35
  • @AndrewWalters, I placed it on top of the View and it works! (??!) Why is that? Because I have another function at the bottom of the View code and it is working fine! Commented Jul 8, 2014 at 13:39
  • The grid was trying to call the function before it was rendered on the page most likely Commented Jul 8, 2014 at 13:40

2 Answers 2

2

The grid is probably firing a Change event immediately on load, and if your java script functions are all defined at the bottom of the page they may not be available yet.

A work around would be moving the text() function up above this grid to ensure it's defined.

Sign up to request clarification or add additional context in comments.

Comments

1

That's odd but according to a bug report in telerik forum (Grid row selection change event not firing) it works fine with jQuery version 1.7.2. Try version 1.7.2 and see it works or not.

1 Comment

+1 for the link and suggestion of newer jQuery version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.