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

Getting new data from the server programatically

3 Answers 55 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 22 Oct 2018, 09:19 PM

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.

 

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 24 Oct 2018, 02:15 PM
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.
0
Bob
Top achievements
Rank 1
answered on 24 Oct 2018, 02:31 PM

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

0
Georgi
Telerik team
answered on 26 Oct 2018, 06:14 AM
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.
Tags
ListBox
Asked by
Bob
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Bob
Top achievements
Rank 1
Share this question
or