React Grid Row Pinning
The Ignite UI for React Row Pinning feature in React Grid allows you to pin one or multiple rows to the top or bottom of grid. Row Pinning allows end-users to pin rows in a particular order, duplicating them in a special area that is always visible even when they scroll the IgrGrid
vertically. The React Grid has a built-in row pinning UI, which is enabled by initializing an IgrActionStrip
component in the context of Grid. In addition, you can define custom UI and change the pin state of the rows via the Row Pinning API.
React Grid Row Pinning Example
Row Pinning UI
The built-in row pinning UI is enabled by adding an IgrActionStrip
component with the IgrGridPinningActions
component. The action strip is automatically shown when hovering a row and will display a pin or unpin button icon based on the state of the row it is shown for. An additional action allowing to scroll the copy of the pinned row into view is shown for each pinned row as well.
<IgrGrid>
<IgrColumn field="Country" header="Country"> </IgrColumn>
<IgrActionStrip key="actionStrip">
<IgrGridPinningActions key="pinningActions"></IgrGridPinningActions>
<IgrGridEditingActions key="editingActions"></IgrGridEditingActions>
</IgrActionStrip>
</IgrGrid>
Row Pinning API
Row pinning is controlled through the pinned
input of the Row
. Pinned rows are rendered at the top of the IgrGrid
by default and stay fixed through vertical scrolling of the unpinned rows in the IgrGrid
body.
gridRef.current.getRowByIndex(0).pinned = true;
You may also use the IgrGrid
's pinRow
or unpinRow
methods of the to pin or unpin records by their ID:
gridRef.current.pinRow('ALFKI');
gridRef.current.unpinRow('ALFKI');
Observe que a ID da linha é o valor da chave primária, definido pela grade ou pela primaryKey
própria instância do registro. Ambos os métodos retornam um valor booleano indicando se sua respectiva operação foi bem-sucedida ou não. Normalmente, o motivo pelo qual eles falham é que a linha já está no estado desejado.
A row is pinned below the last pinned row. Changing the order of the pinned rows can be done by subscribing to the RowPinning
event and changing the InsertAtIndex
property of the event arguments to the desired position index.
function rowPinning(grid: IgrGridBaseDirective, event: IgrPinRowEventArgs ) {
event.detail.insertAtIndex = 0;
}
<IgrGrid autoGenerate="true" rowPinning={rowPinning}>
</IgrGrid>
Pinning Position
Você pode alterar a posição de fixação da linha por meio da pinning
opção de configuração. Ele permite que você defina a posição da área do pino como Superior ou Inferior. Quando definido como Inferior, as linhas fixadas são renderizadas na parte inferior da grade, após as linhas desafixadas. As linhas não afixadas podem ser roladas verticalmente, enquanto as linhas fixadas permanecem fixas na parte inferior.
<IgrGrid id="dataGrid" autoGenerate="true">
</IgrGrid>
var grid = document.getElementById("dataGrid") as IgrGrid;
grid.pinning = { rows: RowPinningPosition.Bottom };
Custom Row Pinning UI
Você pode definir sua interface do usuário personalizada e alterar o estado do pino das linhas por meio da API relacionada.
Via extra column with icon
Digamos que, em vez de uma faixa de ação, você gostaria de mostrar um ícone de alfinete em cada linha, permitindo que o usuário final clique e altere o estado do alfinete de uma linha específica. Isso pode ser feito adicionando uma coluna extra com um modelo de célula contendo o ícone personalizado.
function cellPinCellTemplate(ctx: IgrCellTemplateContext) {
const index = ctx.dataContext.cell.row.index;
return (
<>
<span onPointerDown={(e: any) => toggleRowPin(index)}>📌</span>
</>
);
}
<IgrGrid primaryKey="ID" autoGenerate="false">
<IgrColumn width="70px" bodyTemplate={cellPinCellTemplate}>
</IgrColumn>
</IgrGrid>
Ao clicar no ícone personalizado, o estado do pino da linha relacionada pode ser alterado usando os métodos de API da linha.
function toggleRowPin(index: number) {
const grid = grid1Ref.current;
grid.getRowByIndex(index).pinned = !grid.getRowByIndex(index).pinned;
}
Demo
Row Pinning Limitations
- Somente os registros existentes na fonte de dados podem ser fixados.
- O estado de fixação de linha não é exportado para o Excel. A grade é exportada como se nenhuma fixação de linha fosse aplicada.
- As cópias de linhas fixadas na área rolável da grade são parte integrante de como outros recursos de grade alcançam sua funcionalidade na presença de linhas fixadas e, portanto, sua criação não pode ser desabilitada nem removida.
- As Row Selection works entirely with row Ids, selecting pinned rows selects their copies as well (and vice versa). Additionally, range selection (e.g. using Shift + click) within the pinned area works the same way as selecting a range of rows within the scrollable area. The resulting selection includes all rows in between even if they are not currently pinned. Getting the selected rows through the API only returns a single instance of each selected record.
Styling
Além dos temas predefinidos, a grade pode ser ainda mais personalizada ao definir algumas das propriedades CSS disponíveis. Caso você queira alterar algumas das cores, precisa definir uma classe para a grade primeiro:
<IgrGrid className="grid"></IgrGrid>
Em seguida, defina as propriedades CSS relacionadas para essa classe:
.grid {
--ig-grid-pinned-border-width: 5px;
--ig-grid-pinned-border-style: double;
--ig-grid-pinned-border-color: #FFCD0F;
--ig-grid-cell-active-border-color: #FFCD0F;
}
Demo
API References
Additional Resources
- Virtualização e desempenho
- Paginação
- Filtragem
- Classificação
- Resumos
- Movimentação de Colunas
- Redimensionamento de colunas
- Escolha
Nossa comunidade é ativa e sempre acolhedora para novas ideias.