Edición por lotes y transacciones en cuadrículas Angular
The Batch Editing feature of the IgxGrid is based on the TransactionService. Follow the Transaction Service class hierarchy topic to see an overview of the igxTransactionService and details how it is implemented.
A continuación se muestra un ejemplo detallado de cómo se habilita la edición por lotes para el componente Grid.
Angular Grid Batch Editing and Transactions Example
The following sample demonstrates a scenario, where the grid has batchEditing enabled and has row editing enabled. The latter will ensure that transaction will be added after the entire row edit is confirmed.
Note
El estado de la transacción consta de todas las filas actualizadas, agregadas y eliminadas, y sus últimos estados.
Usage
Para empezar, importa elIgxGridModule archivo en el app.module.ts:
// app.module.ts
...
import { IgxGridModule } from 'igniteui-angular';
@NgModule({
...
imports: [..., IgxGridModule],
...
})
export class AppModule {}
Then, all you need to do is enable batchEditing from your Grid:
<igx-grid [data]="data" [batchEditing]="true">
...
</igx-grid>
This will ensure a proper instance of Transaction service is provided for the igx-grid. The proper TransactionService is provided through a TransactionFactory. You can learn more about this internal implementation in the transactions topic.
Después de habilitar la edición por lotes, define unaIgxGrid fuente de datos con enlace yrowEditable configúralo como verdadero y bind:
<igx-grid #grid [batchEditing]="true" [data]="data" [primaryKey]="'ProductID'" width="100%" height="500px"
[rowEditable]="true">
...
</igx-grid>
...
<button igxButton [disabled]="!grid.transactions.canUndo" (click)="undo()">Undo</button>
<button igxButton [disabled]="!grid.transactions.canRedo" (click)="redo()">Redo</button>
<button igxButton [disabled]="grid.transactions.getAggregatedChanges(false).length < 1"
(click)="openCommitDialog(dialogGrid)">Commit</button>
...
El siguiente código demuestra el uso de latransactions API: deshacer, rehacer, hacer commit.
export class GridBatchEditingSampleComponent {
@ViewChild('grid', { read: IgxGridComponent }) public gridRowEditTransaction: IgxGridComponent;
public undo() {
/* exit edit mode and commit changes */
this.grid.endEdit(true);
this.grid.transactions.undo();
}
public redo() {
/* exit edit mode and commit changes */
this.grid.endEdit(true);
this.grid.transactions.redo()
}
public commit() {
this.grid.transactions.commit(this.data);
this.toggle.close();
}
}
Note
La API de transacciones no gestionará el final de la edición y tendrías que hacerlo tú mismo. Si no,Grid se quedaría en modo edición. Una forma de hacerlo es llamandoendEdit al método correspondiente.
Note
DesactivarrowEditable la propiedad modificaráGrid para crear transacciones al cambiar la celda y no expondrá la superposición de edición de filas en la interfaz.
Remote Paging with Batch Editing Demo
Consulte la configuración de demostración completa
API References
Additional Resources
- Cree operaciones CRUD con igxGrid
- Descripción general de la cuadrícula
- Edición de cuadrícula
- Edición de filas de cuadrícula
- Agregar filas de cuadrícula