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
close icon

Tree Grid data rebind

I am using Tree Grid
I use ajax  to call web api  and bind dataSource of  Tree Grid. I need rebind Tree Grid.
However, I found that if I assign Json object to dataSource again, the grid is not refreshed but new items will add to old items. 
For example, first time I bind 20 items to Tree Grid. And then, I want to refresh grid and bind new 10 items to tree grid again.  However, the new result of the grid is 30 items.

How can I clear grid items and rebind to fresh items?

Tree Grid Code:

<ejs-treegrid id="grid_deliverablelist" idMapping="ID" parentIdMapping="ParentID" treeColumnIndex="1" class="gridlist" allowSelection="true" allowPaging="true" rowSelected="deliverableRowSelected" >
            <e-treegrid-selectionsettings type="Single"></e-treegrid-selectionsettings>
            <e-treegrid-pagesettings pageSize="10"></e-treegrid-pagesettings>
            <e-treegrid-columns>
                <e-treegrid-column field="ID" header-text="Deliverable ID" width="60" is-primary-key="true"></e-treegrid-column>
                <e-treegrid-column field="ProjectID" header-text="Poject Number" width="60"></e-treegrid-column>
                <e-treegrid-column field="Status" header-text="Status" width="80"></e-treegrid-column>
                <e-treegrid-column field="Description" header-text="Description" width="250"></e-treegrid-column>
                <e-treegrid-column field="StartDate" header-text="Start Date" format="{ type:'date', format:'dd/MM/yyyy' }" textAlign="Right" width="80"></e-treegrid-column>
                <e-treegrid-column field="EndDate" header-text="End Date" format="yMd" textAlign="Right" width="80"></e-treegrid-column>
                <e-treegrid-column field="CompletionDate" header-text="Completion Date" format="yMd" textAlign="Right" width="80"></e-treegrid-column>
                <e-treegrid-column field="ParentID" header-text="Parent ID" width="80"></e-treegrid-column>
            </e-treegrid-columns>
        </ejs-treegrid>

Javascript code:
 function RefreshGrid(filterJson) {
        var grid = document.getElementById("grid_deliverablelist").ej2_instances[0];
        $.ajax({
            type: "POST",
            url: '../api/DeliverablesAPI/GetDeliverableList',
            data: JSON.stringify(JSON.stringify(filterJson)),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            success: function (data, status) {
                if (data.Message == "") {
                    grid.dataSource = JSON.parse(data.d);
                    //grid.flatData = JSON.parse(data.d);
                    var a = 0;
                }
                else {
                    alert(data.Message);
                }
            },
            error: function (request, status, error) {
                FormSubmitted = false;
                alert(status + "--" + error + "--" + request.responseText);
            }
        });
    }

1 Reply

VN Vignesh Natarajan Syncfusion Team January 25, 2019 08:37 AM UTC

Hi Tianyu, 

Thanks for contacting Syncfusion support. 

Query: if I assign Json object to dataSource again, the grid is not refreshed but new items will add to old items.  
 
From your query, we understand that you are facing issue while updating the dataSource for TreeGrid. We are able to reproduce the reported issue at our end. We have confirmed that the mentioned issue  “DataSource of TreeGrid is not updated properly using dataSource property” is a bug and have logged a defect report for the same. The fix for this issue will be included in our next patch release on 13th February 2019.     

Until then we suggest you to use the workaround given below. 


function RefreshGrid(filterJson) { 
        var grid = document.getElementById("grid_deliverablelist").ej2_instances[0]; 
        $.ajax({ 
            type: "POST", 
            url: '../api/DeliverablesAPI/GetDeliverableList', 
            data: JSON.stringify(JSON.stringify(filterJson)), 
            contentType: "application/json; charset=utf-8", 
            dataType: "json", 
            async: true, 
            success: function (data, status) { 
                if (data.Message == "") { 
                    grid.flatData = []; 
                    grid.dataSource = JSON.parse(data.d); 
                    var a = 0; 
                } 
                else { 
                    alert(data.Message); 
                } 
            }, 
            error: function (request, status, error) { 
                FormSubmitted = false; 
                alert(status + "--" + error + "--" + request.responseText); 
            } 
        }); 
    } 

Regards,
Vignesh Natarajan. 


Loader.
Live Chat Icon For mobile
Up arrow icon