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