问题
I have a problem with my ag-grid array, I have this array :
<div style="width: 100%;">
<ag-grid-angular #agGrid style="width: 100%; height: 200px;" class="ag-fresh"
[gridOptions]="gridOptions"
[rowData]="rowData"
[columnDefs]="columnDefs"
enableColResize
rowSelection="multiple"
(columnResized)="onColumnEvent($event)"
(columnPinnedCountChanged)="onColumnEvent($event)">
</ag-grid-angular>
</div>
And I have two buttons :
<div class="bouton" placement="top" ngbTooltip="Déplacer instruction vers le haut">
<button (click)="moveUp()">
<img src="/src/images/flechehaut.png" style="width:60px;height:60px;" />
</button>
</div>
<div class="bouton" placement="top" ngbTooltip="Déplacer instruction vers le bas">
<button (click)="moveDown()">
<img src="/src/images/flechebas.png" style="width:60px;height:60px;" />
</button>
</div>
And I was wondering if it was possible to move up an entire row with my move up button and to move down a row with my move down button. I looked on the ag-grid documentation but found nothing about this possibility.
Is it at least possible ? And if it is, how should I look into this problem ?
回答1:
Yes, I can think of two possibilities:
- Rearrange the rowData and reload it in the grid
- This may get costly depending on how many rows you have
- I sure hope you have sorting disabled on all your columns, otherwise your
moveUp
andmoveDown
functions would be useless
- Create a column that has the order of the items in ascending order then your
moveUp
/moveDown
functions would just update this number to one more or less, then you resort the grid based on those new values.- This would keep the order of the rowData the same as when it was initially sent to the grid, but DISPLAY it in a particular order.
- I think it might be possible to hide this extra column and still have it be sorted on said column.
来源:https://stackoverflow.com/questions/43657659/angular2-ag-grid-is-it-possible-to-move-up-down-a-row-with-a-button