#101357
Anonymous
Inactive

Hi Yavor,
Thank you for the reply, I have see the demos and try to reload the datasource for my TreeGrid (I don’t reload the page but only change the datasource in the same smart-grid element), but the smart-grid element is not reloaded with new datasource,┬áthis changes correctly only if I dynamically remove and re-create the smart-grid element. If I recall the same function for 3 times (for example) with 3 different datasource, also the export create 3 files with the first datasource.
In the html page I have the tag:
<smart-grid id=”treeGrid” style=”width: 100%”></smart-grid>
and in the js, when click the button for obtain the datasource, I call this function:
function loadTreeGrid(myDataSourceArray) {
var grid = document.querySelector(‘#treeGrid’);
new window.Smart(‘#treeGrid’, class {
get properties() {
return {
behavior: { columnResizeMode: ‘growAndShrink’ },
filtering: {
enabled: true
},
sorting: {
enabled: false
},
dataSource: new window.Smart.DataAdapter(
{
dataSource: myDataSourceArray,
keyDataField: ‘id’,
parentDataField: ‘idFather’,
id: ‘id’,
dataFields:
[
‘id: number’,
‘idFather: number’,
‘Field1: string’,
‘Field2: string’,
‘Field3: string’,
‘Field4: string’,
‘Field5: number’,
]
}),
columns: [
{
label : ‘Field1’,
dataField : ‘Field1’,
},
{
label : ‘Field2’,
dataField : ‘Field2’,
},
{
label : ‘Field3’,
dataField : ‘Field3’,
},
{
label : ‘Field4’,
dataField : ‘Field4’,
},
{
label : ‘Field5’,
dataField : ‘Field5’,
},
]
}
}
});
var xlsxBtn = document.querySelector(‘#excelExport’);
var htmlBtn = document.querySelector(‘#csvExport’);
xlsxBtn.addEventListener(‘click’, () => {
grid.exportData(‘xlsx’);
});
htmlBtn.addEventListener(‘click’, () => {
grid.exportData(‘html’);
});
}
This is an example format of my Datasource (the stringify of my datasource):
myDataSourceArray=[{“id”:1,”idFather”:0,”Field1″:”0″,”Field2″:”test2″,”Field3″:”10″,”Field4″:”Data2″,”Field5″:1},
{“id”:2,”idFather”:0,”Field1″:”0″,”Field2″:”test1″,”Field3″:”20″,”Field4″:”Data1″,”Field5″:1},
{“id”:0,”idFather”:”null”,”Field1″:”111″,”Field2″:”test3″,”Field3″:”5″,”Field4″:”Data3″,”Field5″:1}]
It’s possible to reload the smart-grid element with different datasource without recreate the element?
Thanks,
Walter Mariani