尝试使用ag-grid库显示行的索引("序号")。
根据序号,我只是指从上到下计数的行号(根据拖动' drop或已应用的任何排序重新排序)。
即。根据附上的截图,我想看看保时捷指数= 0,丰田= 1,福特= 2,拖累"保时捷"到顶部(参见'之前')。但他们指数在重新排序时似乎没有重新计算。
以下是我尝试过的内容(请参阅_getIndexValue
):
import { Grid, GridOptions, ColDef } from "ag-grid/main";
import { ValueGetterParams } from "ag-grid/dist/lib/entities/colDef";
// for ag-grid-enterprise users only
import 'ag-grid-enterprise/main';
import "ag-grid/dist/styles/ag-grid.css";
import "ag-grid/dist/styles/ag-theme-balham.css";
class SimpleGrid {
_getIdValue(args: ValueGetterParams): any {
return args.node.id;
}
_getIndexValue(args: ValueGetterParams): any {
return args.node.rowIndex;
}
private gridOptions: GridOptions = <GridOptions>{};
constructor() {
this.gridOptions = {
columnDefs: this.createColumnDefs(),
rowData: this.createRowData(),
rowDragManaged: true,
};
let eGridDiv:HTMLElement = <HTMLElement>document.getElementById('myGrid');
new Grid(eGridDiv, this.gridOptions);
}
// specify the columns
private createColumnDefs(): ColDef[] {
return [
{headerName: "Index", valueGetter: (args) => this._getIndexValue(args), rowDrag: true},
{headerName: "ID", valueGetter: (args) => this._getIdValue(args)},
{headerName: "Make", field: "make"},
{headerName: "Model", field: "model"},
{headerName: "Price", field: "price"}
];
}
// specify the data
private createRowData() {
return [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];
}
}
window.addEventListener("load", () => {
new SimpleGrid();
});
我希望有比订阅dragEnd事件和强制更新索引更好的方法。
答案 0 :(得分:1)
实施(我最初发布的)如果您订阅RowDragEnd
事件&amp;调用api.refreshCells()
。从性能的角度来看,它可能并不理想,但就我的目的来说,这并不重要。