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

Reference to ChildGrid's GridComponent

I am using nested Grids, I am using custom toolbar items to add advanced features, I need to know which records have been selected.

For the parent Grid I am using "REF" in the grid definition, then grid.getSelectedRecords().
I can't do the same thing for the childs. The "REF" in the definition doesn't seem to work, and neither does grid.childgrid.getSelectedRecords().

You can find the code used attached.

Attachment: Assembly__Copy_6c8fad61.7z

3 Replies

PS Pavithra Subramaniyam Syncfusion Team June 6, 2019 11:36 AM UTC

Hi Matteo, 
 
Greetings from Syncfusion, 
 
You can achieve your requirement by getting the instance in the toolbar click event of the corresponding Grid. Pleas refer to the below code example and sample link for more information. 
 
[index.jsx] 
export class Hierarchy extends SampleBase { 
    constructor() { 
        super(...arguments); 
        this.toolbarSettings = ['Add', 'Edit', 'Delete', 
        { text: 'Copy', prefixIcon: 'e-copy', id: 'cpy' }, 
        { text: 'Attach', prefixIcon: 'e-add', id: 'att' }, 
    ]; 
    this.sequenceToolbarSettings = [ 
        { text: 'Attach', prefixIcon: 'e-link-icon', id: 'att' }, 
        { text: 'Detach', prefixIcon: 'e-unlink-icon', id: 'det' }, 
    ];  
        this.childGrid = { 
            dataSource: orderDatas, 
            queryString: 'EmployeeID', 
            toolbar: this.sequenceToolbarSettings, 
            toolbarClick: this.sequenceClickHandler,  
                                           .  .  . 
        }; 
    } 
    clickHandler = (args) => { 
      if(args.item.id =='att'){ 
        let asm = this.grid.getSelectedRecords(); 
        console.log(asm); 
        return; 
      } 
    } 
    sequenceClickHandler = (args) => { 
      if(args.item.id =='att'){ 
      var seqGrid = parentsUntil(args.originalEvent.target,"e-grid").ej2_instances[0]; 
        let seq = seqGrid.getSelectedRecords(); 
        console.log(seq); 
        return; 
      } 
        
    } 
 
    render() { 
        return (<div className='control-pane'> 
                <div className='control-section'> 
                    <GridComponent dataSource={employeeData} childGrid={this.childGrid}  
                     toolbar={this.toolbarSettings} 
                    toolbarClick={this.clickHandler} 
                    ref={g => this.grid = g} 
                    allowSorting={true}> 
                        <ColumnsDirective> 
                            .  .  . 
                        </ColumnsDirective> 
                        <Inject services={[DetailRow, Toolbar, Page, Sort]}/> 
                    </GridComponent> 
                </div> 
            </div>); 
    } 
} 
 
render(<Hierarchy />, document.getElementById('sample')); 
 
 
Please get back to us, if you need further assistance. 
 
Regards, 
Pavithra S. 



MA Matteo June 18, 2019 02:06 PM UTC

it works great.

Thank you!


PS Pavithra Subramaniyam Syncfusion Team June 19, 2019 04:37 AM UTC

Hi Matteo,  

Thanks for your update. 

We are happy to hear that the provided solution is working. 

Please contact us if you need any further assistance. As always, we will be happy to assist you.  

Regards,  
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon