Is there a Bind event?

2 posts, 0 answers
  1. Randy
    Randy avatar
    67 posts
    Member since:
    Jul 2009

    Posted 17 Apr 2017 Link to this post

    I have a DropdownList on my page. I have it set as follows:

    @(Html.Kendo().DropDownListFor(m => m)
                            .Name("CustomerDropDown")
                            .DataTextField("DropDownText")
                            .DataValueField("RowId")
                            .OptionLabel("Select Customer or Reseller...")
                            .AutoBind(true)
                            .Filter("contains")
                            .HtmlAttributes(new { style = "width:500px" })
                            .DataSource(source =>
                            {
                                source.Read(read =>
                                {
                                    read.Action("GetCustomersForPointofSaleDropDown", "Customer");
                                })
                                .ServerFiltering(true);
                            })
                            .Events(e =>
                            {
                                e.Select("onCustomerSelect").DataBound("onDropDownListBound");
                            })
                        )

    Under certain circumstances I don't want the drop down list to auto bind. I don't see a Bind event I can latch on to, like I can with the data bound event, in order for me to prevent the binding from happening. Is there some way I can prevent the auto binding before it actually occurs?

  2. Dimitar
    Admin
    Dimitar avatar
    683 posts

    Posted 18 Apr 2017 Link to this post

    Hello Randy,

    Thank you for the example provided and the additional clarifications of the issue.

    Currently there is no DataBinding event, with which would allow you to prevent the binding from happening. However, you can check the two solutions below, which might help you to achieve the desired result.

    In the attached file (TelerikMvcAppDropDownList.zip) you will find a simple implementation of the Kendo DropDownList, which prevents the DataSource binding on RequestStart event of the DataSource. The HTML and the JS code to achieve this can be found in Views/Home/Index.cshtml. You will notice that I have added an event handler to the DataSource property and I have executed some custom JS code to stop the request and disable to loading icon:
    e.preventDefault();
    setTimeout(
    function () {

      $(
    '.k-icon').removeClass('k-i-loading');

    }, 200);

    I have also added a "Turn bindings ON" button, which enables the binding of the DataSource.

    Another way to prevent the auto binding would be to manually bind the DropDownList widget with JS only when you need to. For more detailed example you can check the following demo.

    If you have any other questions, please do not hesitate to contact us.

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top