Refresh TreeGrid

I use Treegrid 

                  <ejs-treegrid id="TreeGrid" locale="pl-PL" enableAltRow="true" enableCollapseAll="true" enableHover="true"

                      idMapping="AccId" parentIdMapping="ParId"

                     treeColumnIndex="0"

                      toolbar="@(new List<string>() {"ExpandAll","CollapseAll","Search"})">

            <e-data-manager url="@Url.Action("UrlDataSource","Home")" adaptor="UrlAdaptor" offline="true"></e-data-manager>

            <e-treegrid-columns>

                <e-treegrid-column field="Numer" headerText="Numer" textAlign="Left" width="120"></e-treegrid-column>

                <e-treegrid-column field="Nazwa" minWidth="200" headerText="Nazwa"></e-treegrid-column>

                <e-treegrid-column field="Nazwa2" headerText="Nazwa 2"></e-treegrid-column>

                <e-treegrid-column field="Wn" headerText="Wn" format="N2" width="110" textAlign="Right"></e-treegrid-column>

                <e-treegrid-column field="Ma" headerText="Ma" format="N2" width="110" textAlign="Right"></e-treegrid-column>

                <e-treegrid-column field="OWn" headerText="OWn" format="N2" width="110" textAlign="Right"></e-treegrid-column>

                <e-treegrid-column field="OMa" headerText="OMa" format="N2" width="110" textAlign="Right"></e-treegrid-column>

                <e-treegrid-column field="OTotWn" headerText="Obr. n. Wn" format="N2" width="110" textAlign="Right"></e-treegrid-column>

                <e-treegrid-column field="OTotMa" headerText="Obr. n. Ma" format="N2" width="110" textAlign="Right"></e-treegrid-column>

                <e-treegrid-column field="SWn" headerText="SWn" format="N2" width="110" textAlign="Right"></e-treegrid-column>

                <e-treegrid-column field="SMa" headerText="SMa" format="N2" width="110" textAlign="Right"></e-treegrid-column>

                <e-treegrid-column field="SPer" headerText="Pldo" format="N2" width="110" textAlign="Right"></e-treegrid-column>

            </e-treegrid-columns>

  </ejs-treegrid>


1. Somehow you can refresh the data by clicking the button on the page?

2 Is it possible to use aggregation for counting sums only for rows form level 1



3 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team May 21, 2020 12:25 PM UTC

Hi Krzysztof, 

Thanks for contacting Syncfusion Suppport. 

Query#1:- Somehow you can refresh the data by clicking the button on the page? 
 
We have checked your query and you can refresh the TreeGrid using refresh method on button click.  Also you can refresh the header and columns separately using refreshHeader and refreshColumns methods. 
 
Refer to the API Link:- 

Query#2:- Is it possible to use aggregation for counting sums only for rows form level 1 
 
From your query we suspect that you need to show only total aggregate. To achieve this, we suggest you to set showChildSummary as false.  
Refer to the Demo Link:- 

If the above solution doesn’t meet your requirement, please share us the following details. 

  1. Do you want to show only aggregate values of the ParentNode or any other requirement?
  2. Share screenshot of your requirement.

The provided details will be helpful to provide you response as early as possible. 

Regards, 
Farveen sulthana T 



KR Krzysztof May 23, 2020 02:52 PM UTC

1. When I use the refresh (), refreshHeader (), refreshColumns () methods, DataManager does not download data, if the rows were expanded they remain unchanged, the width of the columns is not set to the default value.

I would need a method that will reset the treegrid to the initial settings and reload the data.

Update  

refresh (), refreshHeader (), refreshColumns () works if we use offline datamanager false,

but how to clear input search ?




2 I have set showChildSummary as false but this does not solve the problem. 

I solved it this way


  function customAggregateFn(data, i) {            

        var resSum = 0;    

        data.result.forEach(function (e) {            

            if (e.level == 0) {

                resSum+=e[i.properties.field];

            }        

        });    

        return resSum;

    }



PK Padmavathy Kamalanathan Syncfusion Team May 25, 2020 02:02 PM UTC

Hi Krzysztof,

Thanks for your update.

QUERY1: How to clear input search?

For clearing the searched value, you can assign empty string to the key value in the searchSettings of Tree Grid before calling the refresh method of Tree Grid in the button click event.

Please check the below code,


  
<ejs-button id="clear" content="Clear"></ejs-button> 
    <ejs-treegrid id="TreeGrid" dataSource="@ViewBag.data"  treeColumnIndex="1"  
 
           allowFiltering="true" toolbar="@(new List<string>() { "Search" })"> 
        <e-data-manager url="@Url.Action("DataSource","Home")" adaptor="UrlAdaptor" > 
       </e-data-manager> 
        ---------- 
    </ejs-treegrid> 
  
    <script> 
        document.getElementById('clear').addEventListener('click', () => { 
            var treegridObj = document.getElementsByClassName("e-treegrid")[0].ej2_instances[0]; 
            //treegrid instance 
            treegridObj.searchSettings.key = ''; // emptying the searched value 
            treegridObj.refresh(); 
        }); 
    </script> 


Please check the below help documentation,

QUERY2: Use aggregate for counting sums only for rows of level 1

We are glad to hear that you have achieve your requirement. Kindly get back to us for further assistance.

Regards,
Padmavathy Kamalanathan



Loader.
Up arrow icon