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

Change MultiSelect DataSource Dynamically ?

1 Answer 922 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
K.Ramadan
Top achievements
Rank 2
Veteran
K.Ramadan asked on 12 May 2020, 07:20 AM

Hello EveryOne,

I'm trying to change the dataSource of a MultiSelect widget.

This is my MultiSelect (in my CustomEditor):

@(Html.Kendo().MultiSelectFor(model => model.Person)
                         //.Name("FirmaAutoSelect")
                         .DataTextField("Name")
                         .MaxSelectedItems(1)
                         .AutoWidth(true)
                         .HtmlAttributes(new { style = "width:100%" })
                         .Events(eve =>
                         {
                             eve.Open("onOpen_Person");
                         })
                         //.ValuePrimitive(true)
                         .DataSource(source =>
                         {
                             source.Custom()
                             //.ServerFiltering(true)
                             .Type("aspnetmvc-ajax")
                             .Transport(transport =>
                             {
                                 transport.Read("Read_Personen", "Person");
                             })
                             .Schema(schema =>
                             {
                                 schema.Data("Data")
                                         .Total("Total")
                                         .Errors("Errors");
                             });
                         })
                    )

 

and i tried in the onOpen_Person function this code :

var person_mult = $("#Person").data("kendoMultiSelect");
                    var dataSource = new kendo.data.DataSource({
                        //batch: true,
                        transport: {
                            read: {
                                url: "/Person/AlleOderFirma_Personen",
                                dataType: "json"                           
                            },
                    //    }
                    //});
                            parameterMap: function (options, operation) {
                                if (operation !== "read" && options.models) {
                                    return { models: kendo.stringify(options.models) };
                                }
                            }
                        },
                        schema: {
                            model: {
                                id: "Sid_personen",
                                fields: {
                                    Sid_personen: { from: "Sid_personen" }
                                }
                            }
                        }
                    });
                    person_mult.setDataSource(dataSource);

 

Now this shows just one item and it's undefined !!

I console.Logged the dataSource and i saw that the "Sid_personen" is undefined .. but in "_data" i found all the items i need .. but it doesn't show them ..

in the attached picture you can see the consoleLogged DataSource.

and this is my ActionMethod:

public ActionResult AlleOderFirma_Personen([DataSourceRequest]DataSourceRequest request)
{
    //string g = Id_Firma;
    using (var db = new cRM_FM_v2_KARAMEntities())
    {
        IQueryable newQuery = db.PERSONEN.ToList().Select(prs => new PersonViewModel()
        {
            Sid_personen = prs.SID_PERSONEN,
            Name = prs.NAME,
            Vorname = prs.VORNAME,
            Recid_firmen = prs.RECID_FIRMEN,
            Crmusername = prs.CRMUSERNAME
        }).AsQueryable();
        return Json(newQuery.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }
}

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 14 May 2020, 06:05 AM

Hello Karam,

Thank you for the provided code snippets.

I used the MultiSelect configuration in the attached project, and it seems to be working as expected. You can see that the new data are being correctly fetched when opening the component. Could you please review and modify the project so that the issue you are experiencing could be observed? I will be able to test it and hopefully discover the source of it.

Looking forward to your reply.

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
MultiSelect
Asked by
K.Ramadan
Top achievements
Rank 2
Veteran
Answers by
Martin
Telerik team
Share this question
or