Search code examples
angularsyncfusionej2-syncfusion

Syncfusion Angular : I want to add multiple rows in grid programmatically


I have question in syncfusion treegrid about add multiple rows programmatically, i can add multiple rows but it add's to the last, but i want to add multiple rows at specified index.

i am sharing a code snippet, please look into it.

copy() {
    this.MultiSelect = true;
    var allselected = this.treegrid.getSelectedRecords();
    var rows = this.treegrid.getSelectedRows();
    this.copiedRow = rows;
    var crows = [];
    for (let index = 0; index < allselected.length; index++) {
      crows.push(allselected[index]['taskData']);
    }
    this.copiedRows = crows;
    this.copiedRow.forEach(x => {
      x.setAttribute('style', 'background:pink;');
    });
}

paste() {
    if(this.copiedRows.length>0)
    {
        var filteredcopiedrows = this.copiedRows;
        var tree = document.getElementsByClassName("e-treegrid")[0]['ej2_instances'][0];
        var temp = tree.dataSource.slice()
        filteredcopiedrows.forEach(data => {
            temp.push(data);
        });
        this.treegrid.dataSource = temp;
        this.dataService.pushData(this.treegrid.dataSource);
        
        this.copiedRow.forEach(x => {
            x.setAttribute('style', 'background:white;');
        });
        this.copiedRows = [];

    }
}

Solution

  • Currently we don’t have support for “Addition of multiple records with RowPosition using addRecord method”. We have logged it as feature improvement. Support for this improvement will be included in any of our upcoming release. Please cast your vote on this feature based on the customer demand we will be implementing the features in our upcoming road map.

    You can now track the current status of this feature with the below feedback link,
    https://www.syncfusion.com/feedback/27035/need-to-provide-support-for-addition-of-multiple-records-using-addrecord-method