Framework:Javascript GridAngular GridReact GridVue Grid

JavaScript Grid: Tool Panel Component

Custom Tool Panel Components can be included into the grid's Side Bar. Implement these when you require more Tool Panels to meet your application requirements.

Simple Tool Panel Component

Below is a simple example of a tool panel component:

class CustomStatsToolPanel {
   init(params) {
       this.eGui = document.createElement('div');
       this.eGui.style.textAlign = "center";

       // calculate stats when new rows loaded, i.e. onModelUpdated
       const renderStats = () => {
           this.eGui.innerHTML = this.calculateStats(params);
       };
       params.api.addEventListener('modelUpdated', renderStats);
   }

   getGui() {
       return this.eGui;
   }

   calculateStats(params) {
       let numGold = 0, numSilver = 0, numBronze = 0;
       params.api.forEachNode(function (rowNode) {
           const data = rowNode.data;
           if (data.gold) numGold += data.gold;
           if (data.silver) numSilver += data.silver;
           if (data.bronze) numBronze += data.bronze;
       });

       return `
       <span>
           <h2><i class="fa fa-calculator"></i> Custom Stats</h2>
           <dl style="font-size: large; padding: 30px 40px 10px 30px">
               <dt style="padding-bottom: 15px">Total Medals: <b>${numGold + numSilver + numBronze}</b></dt>
               <dt style="padding-bottom: 15px">Total Gold: <b>${numGold}</b></dt><dt style="padding-bottom: 15px">Total Silver: <b>${numSilver}</b></dt>
               <dt style="padding-bottom: 15px">Total Bronze: <b>${numBronze}</b></dt>
           </dl>
       </span>`;
   }
}

Example: 'Custom Stats' Tool Panel Component

The example below provides a 'Custom Stats' Tool Panel to demonstrates how to create and register a Custom Tool Panel Component with the grid and include it the Side Bar:

Tool Panel Interface

Implement this interface to create a tool panel component.

interface IToolPanel {
   // The init(params) method is called on the tool panel once upon component initialisation.
   init(params: IToolPanelParams): void;

   // Returns the DOM element for this Tool Panel
   getGui(): HTMLElement;

   // Can be left blank if no custom refresh logic is required.
   refresh(): void;
}

The interface for the init parameters is as follows:

interface IToolPanelParams {
    // Grid API
    api: GridApi;
    
    // Column API
    columnApi: ColumnApi;
}

Registering Tool Panel Components

Registering a Tool Panel component follows the same approach as any other custom components in the grid. For more details see: Registering Custom Components.

Once the Tool Panel Component is registered with the grid it needs to be included into the Side Bar. The following snippet illustrates this:

const gridOptions: {
   sideBar: {
       toolPanels: [
           {
               id: 'customStats',
               labelDefault: 'Custom Stats',
               labelKey: 'customStats',
               iconKey: 'custom-stats',
               component: 'customStatsToolPanel',
           }
       ]
   },
   components: {
       customStatsToolPanel: CustomStatsComponent
   }

   // other grid properties
}

For more details on the configuration properties above, refer to the Side Bar Configuration section.