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

Grid: Migrating from Telerik Extensions for ASP.NET MVC

1 Answer 457 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eduardo
Top achievements
Rank 1
Eduardo asked on 30 Jul 2012, 02:58 PM
Hello I need help to find how to write 2 events.
1_ OnDatabinding not exist inEvents(events => events....
2_ OnComplete not exist in Events(events => events....

In KendoUI I not find how to write the events "DataBinding" and "Complete" to call javascript functions.

@(Html.Kendo().Grid(Model.Sors)
        .Name("Grid")
        .EnableCustomBinding(true)
        .Columns(columns =>
        {
            columns.Bound(o => o.TransactionId).Width(20).Title("<input id='selectAll' type='checkbox' /").Sortable(false);
            columns.Bound(o => o.StaffName).Width(100).Title(LocaleUtil.Get(GuestMessageKeys.StaffName));
            columns.Bound(o => o.BuildingName).Width(100).Title(LocaleUtil.Get(BuildingMessageKeys.Building));
            columns.Bound(o => o.DateTime).Width(120).Title(LocaleUtil.Get(GlobalMessageKeys.DateTime)).Format(TelerikUtil.GetShortDateTimeFormat());
            columns.Bound(o => o.TransactionId).Width(30).Title(LocaleUtil.Get(GlobalMessageKeys.Change)).Sortable(false);
        })
        .Events(events => events.DataBound("Grid_OnDataBound"))
        .Events(events => events.DataBinding("Grid_OnDataBinding"))
        .Events(events => events.Complete("Grid_OnComplete"))
        .DataSource(dataBinding => dataBinding
            .Ajax()
            .Read("_KCustomBinding", "MassSorUpdate", new { Area = "MassProcessing" })
            .Total(Model.SorsTotal))
        .Pageable()
        .Sortable()
    )

My javascript
// Send additional data to the grid action method, in this case the ComboBox selected value.
function Grid_OnDataBinding(e) {
    e.data = { id: $("#UpdateType").val() };
    // uncheck select all combo
     $("#selectAll").attr("checked", false);
}
 
var totalGridRecords = 0;
function Grid_OnComplete(e) {
    totalGridRecords = e.response.total;
}
 
function Grid_OnDataBound(e) {
    e.row.cells[0].innerHTML = "<input type='checkbox' name='checkedRecords' value='" + e.dataItem.TransactionId + "' />";
    e.row.cells[4].innerHTML = "<a href='javascript:;' onclick='ShowSorDetailPopup( { transactionId: \"" +e.dataItem.TransactionId+ "\"})'>" + msgDetail + "</a>";
}

My customBinding where I need an "int id"
[GridAction(EnableCustomBinding = true)]
        public ActionResult _KCustomBinding([DataSourceRequest(Prefix = "Grid")] DataSourceRequest request, int id)
        {
            if (request.PageSize == 0)
            {
                request.PageSize = 10;
            }
 
            ViewClientFilter<SorDTO> viewClientFilter = new ViewClientFilter<SorDTO>();
            viewClientFilter.AddPageCount(request.PageSize);
            viewClientFilter.AddPageIndex(request.Page);
 
            ClientFiltersResponse<SorDTO> list = this.MassSorUpdateRepository.GetMassSorUpdatesList(id, viewClientFilter);
 
            return View(new GridModel
            {
                Data = list.Data,
                Total = list.Total
            });
        }

So how can I write these two events for the grid?
1_ DataBinding
2_ Complete

In Telerik I have this:
....
.ClientEvents(s => s.OnRowDataBound("Grid_OnDataBound"))
            .ClientEvents(s => s.OnDataBinding("Grid_OnDataBinding"))
            .ClientEvents(s => s.OnComplete("Grid_OnComplete"))
            .DataBinding(dataBinding => dataBinding.Ajax().Select("_CustomBinding", "MassSorUpdate", new { Area = "MassProcessing" }))
            .Pageable(settings => settings.Total(Model.SorsTotal))
            .EnableCustomBinding(true)
            .Sortable()

UPDATE:
==================================


Now I made this change and the grid call the action
.Ajax()
            // Enable batch mode
            .Batch(true)
            .Read(read => read.Action("_KCustomBinding", "MassSorUpdate", new { Area = "MassProcessing" })
                .Data("Grid_OnDataBinding"))
            .Total(Model.SorsTotal)

But it give me a null reference error on Sorts:
if (request.Sorts.Count == 0)   <= Sorts is = null or undefined

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 31 Jul 2012, 10:31 AM
Hi again Eduardo,

I already replied in the supported ticket you opened. For convenience I will paste it here also.

Most of the changes and issues related to migration from the MVC Wrappers to Kendo Wrappers for MVC are covered in this migration section of the documentation.
The OnComplete does not currently have equivalent and the OnDataBinding is the RequestStart event of the DataSource.

Also to send additional data to the server when the Grid performs a request you should now use the Data method to specify the name of the JavaScript function
e.g.
read.Action("Action", "Controller").Data("someJSfunctionName")


All the best,
Petur Subev
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
Eduardo
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or