Getting new data from the server programatically

4 posts, 0 answers
  1. Bob
    Bob avatar
    4 posts
    Member since:
    Sep 2018

    Posted 22 Oct 2018 Link to this post

    Telerik UI for ASP.NET MVC

    I have wrongly assumed that the ListBox would work the same or similar to the grid.

    I have created and populated a ListBox

    cshtml..

    @(Html.Kendo().ListBox()
            .Name(componentName: "lstRewindRolls")
            .Selectable(ListBoxSelectable.Single)
            .HtmlAttributes(new { tabindex = -1, @class = "k-listbox", style = "background-color:black; color:white; height:450px" })
            .DataValueField("DoffID")
            .DataTextField("RollID")
            .DataSource(dataSource => dataSource
                .Read(read => read.Action(actionName: "GetRolls", controllerName: "Rewind").Data("{ DispositionCode: 'R' }"))
            )
            .Events(events=>  events.Change("RewindRollSelected"))
    )

     

    controller...

    public JsonResult GetRolls(string DispositionCode)
    {
        try
        {
            var result = db.tblRolls.Where(r => r.strDispositionCode == DispositionCode && r.dtmInventoryRemoved == null)
                .Join(db.tblProductSKUs, p => p.lngProductSKUID, q => q.lngProductSKUID, (r, q) => new { r, q })
                .Join(db.tblProducts, s => s.q.lngProductID, t => t.lngProductID, (s, t) => new { s, t })
            .Select(o => new
            {
                DoffID = o.s.r.lngDoffID.ToString(),
                LaneID = o.s.r.strLaneID,
                RollID = o.s.r.lngDoffID.ToString() + o.s.r.strLaneID
            }).OrderBy(t => new { t.DoffID, t.LaneID }).ToList();
            ;
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex)
        {
              ...
          }

     

    When the page loads the ListBox is populated as expected.

    Once I have processed an item in the list, if appropriate (the disposition changed) I want it removed from the list.

    I thought I could simply do a dataSource.read()

    var lstBox = $("#lstRewindRolls").data("kendoListBox");
    lstBox.dataSource.read();

     

    I also tried

    var lstBox = $("#lstRewindRolls").data("kendoListBox");
    lstBox.dataSource.read({ DispositionCode: 'R' });

     

    I cannot seem to get it to work.

    Please help.

     

  2. Georgi
    Admin
    Georgi avatar
    580 posts

    Posted 24 Oct 2018 Link to this post

    Hi Bob,

    Generally speaking both the grid and the listbox internally use a Kendo DataSource. The dataSource is not aware of the widget that uses its data - the only concern of the dataSource is to manage the data. In other words, it does not behave differently in different widgets.

    I have tested the described behavior on my end, but calling hte read method through the dataSource property of a Listbox requests the remote service and rebinds the widget to the response as expected. For your convenience I am attaching the sample I used for testing. Please examine it and let me know if I am missing something.


    Regards,
    Georgi
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Bob
    Bob avatar
    4 posts
    Member since:
    Sep 2018

    Posted 24 Oct 2018 in reply to Georgi Link to this post

    Which was my assumption. I've got numerous widgets throughout my app all using the Kendo DataSource and they are all working as expected and using this same approach.

    My code basically looks like yours, but for whatever reason, I guess I'll have to figure it out, my code...

    var lstBox = $("#lstRewindRolls").data("kendoListBox");
    lstBox.dataSource.read();

    ...never hits the controller

  4. Georgi
    Admin
    Georgi avatar
    580 posts

    Posted 26 Oct 2018 Link to this post

    Hello Bob,

    Indeed your configuration is valid and I did not notice anything that might cause an issue.

    Nevertheless, could you please make sure there are no JS errors in the console of your browser?

    Having said that, sharing a demo that clearly replicates the issue would definitely help us fully understand the case and we will be able to provide further assistance to the best of our knowledge.


    Regards,
    Georgi
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top