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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

132834 Sep 24,2017 08:21 AM Sep 25,2017 05:05 AM JavaScript 1
loading
Tags: ejDropDownList
Paul Kocher
Asked On September 24, 2017 08:21 AM

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)

Keerthana Rajendran [Syncfusion]
Replied On September 25, 2017 05:05 AM

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   
   
  
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;