Group Caption Template:Grid provides an option customize the Group caption values and it can be achieved using the captionTemplate of the groupSettings property of the Grid. Problem discussionSince the customization of the caption template left to the user-end, Grid will not internally process the value and change them to required format (as displayed in the respective Grid column). SolutionTo overcome the discussed problem, we can use the custom helper function with the caption template. Render the Template in HTMLDeclare the caption Template with the with the helper function . <script id="captiontemplate" type="text/x-template"> GroupCaption: ${groupCap(data)} </script> <div id="Grid"> </div>
Define the GridDefine the Grid columns and captionTemplate with the required number of grouped columns (if needed). let data: Object = new DataManager(orderData as JSON[]).executeLocal(new Query().take(15)); let grid: Grid = new Grid( { dataSource: data, groupSettings: { captionTemplate: '#captiontemplate', columns: ['OrderID', 'OrderDate', 'Freight'] }, allowGrouping: true, columns: [ { field: 'OrderID', headerText: 'Order ID', width: 120, textAlign: 'Right' }, { field: 'CustomerName', headerText: 'Customer Name', width: 150 }, { field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'Right' }, { field: 'Freight', width: 120, format: 'C2', textAlign: 'Right' }, { field: 'ShippedDate', headerText: 'Shipped Date', width: 140, format: 'yMd', textAlign: 'Right' }, { field: 'ShipCountry', headerText: 'Ship Country', width: 150 } ] }); grid.appendTo('#Grid');
Define Helper functionDefine the helper function that has been declared in the caption template.
OutputFigure 1: Grouped Grid with the customized caption templates Typescript demo: https://stackblitz.com/edit/rgfzza-nabzx1?file=index.ts Angular Demo: https://stackblitz.com/edit/format-group-caption-ocx95o?file=app.component.ts React Demo: https://stackblitz.com/edit/react-1dqrg8?file=index.js
|
This page will automatically be redirected to the sign-in page in 10 seconds.