Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

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

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...