We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How can I select the initial value if this might be different at times?

Hi!

I'm using the actionComplete event to initialize a schedule and want to use the change event to only refresh the appointments and resources of the schedule.

Now I realized that if I use "selectedIndex" on the DropDownList, both events will eventually fire because the selectedIndex seems to trigger the "change" event.

I used console.log to see which one fires first and it actually is the change event being run first.

So now in order to make use of the "change" event I would have to initialize the schedule everytime I select a different item in the DropDownList.

Thinking about it I wanted to use the "value" member of the DropDownList to set the initial value - the items in the list are ordered alphabetically so if I add another entry to the dataSource the first item right now probably wouldn't be the first one.

What I tried:

I ran a query to get the Id of the first element:

var firstId = '';
        var dataManager = ej.DataManager("/Dienst/GetVersorgung");
        var query = ej.Query().select("Id").take(1);
        var execute = dataManager.executeQuery(query) // executing query
            .done(function (e) {
                firstId = e.result[0].Id;
            });

then I tried to assign this to the value member:

$('#versorgung').ejDropDownList({
            dataSource: dataManager,
            fields: {
                text: 'FullName',
                value: 'Id'
            },
            value: firstId
            [.....]

this doesn't work. When I console.log(firstId) I get the following: be46d25a-7932-4433-a3a5-a27de1a67387
When I copy this and set value: "be46d25a-7932-4433-a3a5-a27de1a67387" everything works.

Is there a way to fix this? How can I make sure always the first entry of the dataSource gets selected (by using the value member)

1 Reply

KR Keerthana Rajendran Syncfusion Team September 25, 2017 09:05 AM UTC

Hi Paul,   
   
Thank you for contacting Syncfusion support.   
   
We have prepared a simple sample based on your requirement. Please refer to the below given link   
   
   
We suggest you to set the value property via setModel of DropDownList in actionComplete event which will be triggered after fetching the data and you can get the result of executed query in arguments of actionComplete event. Please refer to the below given code   
   
$('#customerList').ejDropDownList({   
          dataSource: dataManager,   
          fields: {   
            text: "CustomerID"   
          },   
          query: query,   
          actionComplete:function(args)   
          {   
            this.option("value",args.e.result[0].CustomerID)   
          }   
        });   
   
   
   
Regards,   
Keerthana   
   
  
 


Loader.
Up arrow icon