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

databound event doesn't fire if server binding is used?

5 Answers 580 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Avitot
Top achievements
Rank 1
Avitot asked on 06 Aug 2012, 06:24 AM
Is this the actual implementation of kendo grid?
I wanted to have something like:
@(Html.Kendo().Grid(Model)
      .Name("Foo")
      .Events(e => e.DataBound("server_databound"))
)
and my script:
<script>
function server_databound(){
      alert("hey there!");
}
</script>

when the grid is loaded, the alert isn't fired until I included these:
.DataSource(ds => ds
     .Ajax()
)

is kendo grid's databound event only fired with ajax binding?
what may be a cleaner workaround for this that you might suggest?

5 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 06 Aug 2012, 07:08 AM
Hello Avitot,

If you are using server binding the Grid is bound on server and serialized and initialized on client. What it means is that it is already data bound. You can simple handle load event of the document( $(document).ready(function() { /*...my closure... */}) ) as any grid action will result in page reload.

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
Avitot
Top achievements
Rank 1
answered on 06 Aug 2012, 07:47 AM
Hi Nikolay,

Thanks for the immediate reply. I want to have this function called on grid data bound:
function CheckIfEmpty(e) {
  if (e.sender._data.length == 0) {
    var colspan = e.sender.columns.length;
    $(e.sender.tbody).append("<td colspan ='" + colspan + "'><span> No record(s) found.</span></td>");
    }
  }

My grid is in a partial view that loads data upon changing the selected value of a combo box. The page doesn't load with the grid. How would I implement this?

Cheers!
Avitot
0
Nikolay Rusev
Telerik team
answered on 09 Aug 2012, 06:46 AM
Hello Avitot,

If I understand you question correctly the following line should be executed immediately after the partial view is loaded.
$(document).ready(function() {
 CheckIfEmpty();
});


The above code should be in your partial view, but notice that no args will be passed to the function so e.sender will be undefined.

All the best,
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
Avitot
Top achievements
Rank 1
answered on 09 Aug 2012, 08:40 AM
Hello Nikolay,

Yes, that's what I meant. If that's so, then the grid helper code:
.Events(e => e.DataBound("anyFunction"))
is not applicable in server bound but only in ajax bound. Then I have to use my other option.
0
Nikolay Rusev
Telerik team
answered on 14 Aug 2012, 08:00 AM
Hello Avitot,

Indeed, client-side events will not be raised in server bound mode.
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/troubleshooting#client-side-events-are-not-raised-in-server-bound-mode

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!
Tags
Grid
Asked by
Avitot
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Avitot
Top achievements
Rank 1
Share this question
or