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

Set selected item in Nested List

Thread ID:





147469 Sep 11,2019 06:11 PM UTC Sep 12,2019 10:53 AM UTC JavaScript - EJ 2 1
Tags: ListView
Asked On September 11, 2019 06:11 PM UTC

Hi, how can I define the selected item in Neste List?

For example:

var myList = [ 
  {id: '1', text: 'Images', child: [] }, 
  {id: '2', text: 'Videos', child: [
      {id: '2-1', text: 'Movies', child: [
           {id: '2-1-1', text: 'Movie A', child: [] }
       ] },
   ] }, 

var params = {
  fields: { text: 'text', iconCss: 'icon' },
  select: onSelect,

var listView = new ej.lists.ListView(params );
listView.dataSource = myList ;

I want to start the listView showing the Movies content, how can I do that? Can I pass a path to select the item? Can the sub-items repeats the parents id?

Vinoth Kumar Sundara Moorthy [Syncfusion]
Replied On September 12, 2019 10:53 AM UTC

Hi Lucas, 
Thank you for contacting Syncfusion support. 
Query #1: To start the listView showing the Movies content 
We can achieve your requirement by using “selectItem” method. You can select the item only after the ListView was append in DOM and need to pass the parent Id to selectItem method as like in below code snippet, 
Code Snippet 
//Initialize ListView component 
let nestedListObj: ListView = new ListView({ 
    //Set defined data to dataSource property 
    dataSource: nestedListData, 
    //Map appropriate columns to fields property 
    fields: { iconCss: 'icon', tooltip: 'text' }, 
    //Set true to show icons 
    showIcon: true, 
    //Set header title 
    headerTitle: 'Folders', 
    //Set true to show header title 
    showHeader: true 
nestedListObj.selectItem({ id: '04' }); //To Select parent 
nestedListObj.selectItem({ id: '04-01' }); //To Select parent with chid item 
Query #2: Can I pass a path to select the item? 
No, you can pass only the item’s text or id. 
Query #3: Can the sub-items repeat the parents id? 
No, Unique id is must be assigned for each item in the ListView. 
Could you please check the above details and get back to us if you need any further assistance on this? 
Vinoth Kumar S 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon