ejs-grid [dataSource]="rows"
[allowSorting]="true"
[allowMultiSorting]='true'
[sortSettings]="sortSettings"
[allowFiltering]='true'
[filterSettings]='filterOptions'
[editSettings]='editSettings'
[groupSettings]="groupSettings"
[allowGrouping]="true"
height=600 [enableVirtualization]=true
(cellSaved)="cellSaved($event)"
>
<e-columns>
<e-column field='node' headerText="{{'txt.Node' | translate}}"
[allowEditing]="false" [visible]="false"></e-column>
<e-column field='accessoryId' headerText="{{'txt.NodePart' | translate}}"
[allowEditing]="false" [visible]="false"></e-column>
<e-column field='accessory.accessoryName' headerText="{{'txt.NodePart' | translate}}"
[allowEditing]="false" [visible]="false"></e-column>
<e-column field='accessory.objectOccurrence' headerText="{{'txt.NodePart' | translate}}"
[allowEditing]="false" [visible]="false"></e-column>
<e-column field='accessoryMaterial' headerText="{{'txt.Material' | translate}}"
[allowEditing]="false" [visible]="false"></e-column>
<e-column field='component.accessoryName' headerText="{{'txt.Component' | translate}}"
[allowEditing]="false" [visible]="false"></e-column>
<e-column field='component.objectOccurrence' headerText="{{'txt.Component' | translate}}"
[allowEditing]="false" [visible]="false"></e-column>
<e-column field='componentMaterial' headerText="{{'txt.Component' | translate}}"
[allowEditing]="false" [visible]="false"></e-column>
<e-column field='property.name' headerText="{{'txt.Property' | translate}}"
[allowEditing]="false">
<ng-template #template let-data>
{{data.property.name | translate}}
</ng-template>
</e-column>
<e-column field='property.value' headerText="{{'txt.Value' | translate}}" textAlign='Right'>
<ng-template #template let-data>
<div [ngClass]="{ 'scs-cell-editable': isPropertyEditable(data)}">
{{data.property.value}}
</div>
</ng-template>
</e-column>
<e-column field='property.selectedUnit' headerText="{{'txt.Unit' | translate}}" [edit]='unitProfilesEditParam'>
<ng-template #template let-data>
<div [ngClass]="{ 'scs-cell-editable': isPropertyEditable(data)}">
{{data.property.selectedUnit | translate}}
</div>
</ng-template>
</e-column>
<e-column field='dataSource.name' headerText="{{'txt.DataSource' | translate}}">
<ng-template #template let-data>
<div [ngClass]="{ 'scs-cell-editable': isDataSourceEditable(data)}">
{{data.dataSource.name | translate}}
</div>
</ng-template>
</e-column>
<e-column field='selectedDataSource' headerText="selectedDataSource" [visible]="false"></e-column>
<e-column field='isVisible' headerText="isVisible" [visible]="false"></e-column>
</e-columns>
</ejs-grid>
This is my component options in the onInit of the component:
this.filterOptions = {
columns: [
{field: 'selectedDataSource', matchCase: false, operator: 'equal', predicate: 'and', value: true},
{field: 'isVisible', matchCase: false, operator: 'equal', predicate: 'and', value: true}
]
};
this.editSettings = {
allowEditing: true, mode: 'Batch'
};
this.groupSettings = {
showGroupedColumn: true,
showDropArea: false,
columns: ['node', 'accessoryId', 'accessoryMaterial', 'componentMaterial']
};
this.sortSettings = {
columns: [
{field: 'node', direction: 'Ascending', isFromGroup: true},
]
};
export class AppComponent implements OnInit {
@ViewChild('grid', { static: true }) public grid: GridComponent;
public data: object[];
-------
ngOnInit(): void {
this.sortSettings = {
columns: [
{ field: 'CustomerID', direction: 'Descending' },
]
};
}
created(args) {
// bind the groupsetting in grid’s created event
this.grid.groupSettings = {
columns: ['CustomerID', 'OrderID', 'ShipAddress.ShipCity']
};
}
}
|
ej.grids.Grid.Inject(ej.grids.Filter);
var datas = [{ OrderID: 1, CustomerID: 'SDTH', ShipCity: 'GB', ShipName: null, ShipCountry: '' },
{},
{ OrderID: 2, CustomerID: 'THYH', ShipCity: 'gc', ShipName: null, ShipCountry: null },
{ OrderID: 3, CustomerID: 'YHUJ', ShipCity: null, ShipName: null, ShipCountry: '' },
{ OrderID: 4, CustomerID: 'HNYT', ShipCity: undefined, ShipName: null, ShipCountry: 'j' }]
var grid = new ej.grids.Grid({
dataSource: datas,
allowFiltering: true,
allowSorting: true,
filterSettings: { type: 'Menu' },
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 100 },
{ field: 'ShipCity', headerText: 'Ship City', width: 100, type: 'string', sortComparer: sortComparer }
],
height: 273
});
grid.appendTo('#Grid');
function sortComparer(reference, comparer, refrenceObj, comparerObj) {
// perform sorting action as you need to show in the grid
if (reference < comparer || reference == undefined || reference == null) {
return -1;
}
if (reference > comparer || comparer == undefined || comparer == null) {
return 1;
}
return 0;
}
|