cancel
Showing results for 
Search instead for 
Did you mean: 

select first item in list issue

Former Member
0 Kudos

Hi All,

While i navigate from detail1  page to another master2-detail2 page , i have to select first record in master2 by default while laoding master2-detail2.

but it is not working and no error in console also.

below is my code for default selection.

in master2 controller and in onInit() method i have written code as below.

this.waitForInitialListLoading(function() {

  //On the empty hash select the first item

  this.selectFirstItem();

  });

waitForInitialListLoading: function(fnToExecute) {

  jQuery.when(this.oInitialLoadFinishedDeferred).then(jQuery.proxy(fnToExecute, this));

  },

selectFirstItem: function() {

  var oList = this.getView().byId("list2");

  var aItems = oList.getItems();

  if (aItems.length) {

  oList.setSelectedItem(aItems[0], true);

  }

  },

please help

Regards,

Vamsi

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos
Former Member
0 Kudos

Hi Sai,

I have applied the same code but still it is not working and no error in console.

Regards,

vamsi

antonette_oberholster
Active Contributor
0 Kudos

Hallo

Have you cleared the cache?

Regards

Antonette

Former Member
0 Kudos

Hi,

  1.      var list = new sap.m.List({ 
  2.      id : "yourlist"
  3.      updateFinished : function(oEvent){  
  4.           var firstItem = this.getView().byId("yourlist").getItems()[0];  
  5.           this.getView().byId("yourlist").setSelectedItem(firstItem,true);  
  6.           // perform further neede code here..like modfieng detail page based upon first item 
  7.           } 
  8.      }); 

Try this

Former Member
0 Kudos

Hi Pradeep ,

the above code is also not working .

regards,

Vamsi

saivellanki
Active Contributor
0 Kudos

Hi Vamsi,

Were you able to get items here ?

  var oList = this.getView().byId("list2");

  var aItems = oList.getItems();

Put a breakpoint and check the variable aItems. If data is available then these methods should work

aItems[0].setSelected(true);

oList.setSelectedItem(items[0],true);


Regards,

Sai Vellanki.

Former Member
0 Kudos

Hi Sai,

i could see the data in aItems[0]  in debug mode and date getting displayed in master view.

regards,

Sarath

saivellanki
Active Contributor
0 Kudos

Vamsi,


Then this should work - aItems[0].setSelected(true). Can you show me the console result when it is aItems()[0].

Also, In which controller you are writing this code? Master2/Detail2? Try writing this code in onAfterRendering life cycle hook and check.

Regards,

Sai Vellanki.

Former Member
0 Kudos

Hi Sai,

my code is in master2 controller and

below is my code and console result :

onAfterRendering: function(evt) {

  var x = 5;

  //Wait for the list to be loaded once

  this.waitForInitialListLoading(function() {

  //On the empty hash select the first item

  this.selectFirstItem();

  });

  },

waitForInitialListLoading: function(fnToExecute) { 

  jQuery.when(this.oInitialLoadFinishedDeferred).then(jQuery.proxy(fnToExecute, this));

  },

  selectFirstItem: function() { 

  var oList = this.getView().byId("list2");

  var aItems = oList.getItems();

  if (aItems.length) {

// oList.setSelectedItem(aItems[0], true);

  aItems[0].setSelected(true);

  }

  },

Console result  for aItems[0]   :

aItems[0]

f {bAllowTextSelection: true, mEventRegistry: Object, sId: "__xmlview3--mainListItem2", mProperties: d, mAggregations: Object…}_active: false_oFavIcon: f_oFlagIcon: f_oPlaceholderIcon: f_oSingleSelectControl: f_oTitleText: f_sOwnerId: "__component0"_sapui_bInAfterRenderingPhase: trueaBeforeDelegates: Array[0]aDelegates: Array[0]bAllowTextSelection: truebOutput: truebSelectedDelayed: undefinediSuppressInvalidate: 0mAggregations: ObjectmAssociations: ObjectmBindingInfos: ObjectmBindingParameters: nullmBoundObjects: ObjectmElementBindingContexts: ObjectmEventRegistry: ObjectmMethods: ObjectmProperties: dmSkipPropagation: ObjectoBindingContexts: ObjectoModels: ObjectoParent: f_aNavSections: Array[2]0: "__xmlview3--list2-listUl"1: "__xmlview3--list2-trigger"length: 2__proto__: Array[0]_aSelectedPaths: Array[0]_bItemNavigationInvalidated: true_bReceivingData: false_bRendering: false_bSelectionMode: true_bUpdating: false_oGrowingDelegate: B.extend.constructor_oSelectedItem: f_active: false_oFavIcon: f_oFlagIcon: f_oPlaceholderIcon: f_oSingleSelectControl: f_oTitleText: f_sOwnerId: "__component0"_sapui_bInAfterRenderingPhase: trueaBeforeDelegates: Array[0]aDelegates: Array[0]bAllowTextSelection: truebOutput: truebSelectedDelayed: undefinediSuppressInvalidate: 0mAggregations: ObjectmAssociations: ObjectmBindingInfos: ObjectmBindingParameters: nullmBoundObjects: ObjectmElementBindingContexts: ObjectmEventRegistry: ObjectmMethods: ObjectmProperties: dmSkipPropagation: ObjectoBindingContexts: ObjectoModels: ObjectoParent: foPropagatedProperties: ObjectsBindingPath: nullsId: "__xmlview3--mainListItem2"sParentAggregationName: "items"__proto__: d_sLastMode: "SingleSelectMaster"_sOwnerId: "__component0"_sapui_bInAfterRenderingPhase: trueaBeforeDelegates: Array[0]aDelegates: Array[1]bAllowTextSelection: truebOutput: truebUseExtendedChangeDetection: trueiSuppressInvalidate: 0mAggregations: ObjectmAssociations: ObjectmBindingInfos: ObjectmBindingParameters: nullmBoundObjects: ObjectmElementBindingContexts: ObjectmEventRegistry: ObjectmMethods: ObjectmProperties: dmSkipPropagation: ObjectoBindingContexts: ObjectoModels: ObjectoParent: foPropagatedProperties: ObjectsBindingPath: nullsId: "__xmlview3--list2"sParentAggregationName: "content"__proto__: doPropagatedProperties: ObjectsBindingPath: nullsId: "__xmlview3--mainListItem2"sParentAggregationName: "items"__proto__: d

Regards,

Vamsi

saivellanki
Active Contributor
0 Kudos

Hi Vamsi,

Just do like this and check -



onAfterRendering: function() {

var oList = this.getView().byId("list2");

var aItems = oList.getItems();

  if (aItems.length) {

  aItems[0].setSelected(true);

  }

}

Regards,

Sai Vellanki.

Former Member
0 Kudos

Thank you all for your quick responses and solutions.

it is working when i use updateFinished  event in the list and enabled the required fields in detail page as

i have disabled those fileds in another event .


Regards,

Vamshi

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Can u try this

$('#listid:first-child').attr('selected',true);

Its selected using jquery!

Former Member
0 Kudos

Hi Pradeep,

it is not working

Regards,

Vamsi

Former Member
0 Kudos

Hi,

Can you inspect element of the list and show the items of list and its CSS as pic!

karthikarjun
Active Contributor
0 Kudos

Hi Vamshi,

Will this help?

Fiori app - Select the first line item in split... | SCN

Thanks,

Karthik A