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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Tree Grid data rebind

Thread ID:

Created:

Updated:

Platform:

Replies:

142283 Jan 24,2019 11:07 PM UTC Jan 25,2019 08:37 AM UTC ASP.NET Core - EJ 2 1
loading
Tags: Tree Grid
Tianyu
Asked On January 24, 2019 11:07 PM UTC

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);
            }
        });
    }

Vignesh Natarajan [Syncfusion]
Replied On 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. 


CONFIRMATION

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