Angular2 + Ag-grid - Is it possible to move up/down a row with a button?

眉间皱痕 提交于 2019-12-13 08:27:05

问题


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:

  1. 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 and moveDown functions would be useless
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!