Web Components Fijación de columnas de cuadrícula de árbol
The Ignite UI for Web Components Column Pinning feature in Web Components Tree Grid enables developers to lock specific columns in a desired order, ensuring visibility all the time even when users scroll horizontally through the IgcTreeGridComponent. There’s an integrated UI for Column Pinning, accessible via the Web Components Tree Grid toolbar. Additionally, developers have the flexibility to build a custom user interface which changes the pin state of the columns.
Web Components Tree Grid Column Pinning Example
This example demonstrates how you can pin a column or multiple columns to the left or right side of the IgcTreeGridComponent.
Column Pinning API
Column pinning is controlled through the pinned property of the IgcColumnComponent. Pinned columns are rendered on the left side of the IgcTreeGridComponent by default and stay fixed through horizontal scrolling of the unpinned columns in the IgcTreeGridComponent body.
<igc-tree-grid id="treeGrid" primary-key="ID" foreign-key="ParentID" auto-generate="false">
<igc-column field="Name" pinned="true"></igc-column>
<igc-column field="Title"></igc-column>
<igc-column field="ID"></igc-column>
</igc-tree-grid>
You may also use the IgcTreeGridComponent's PinColumn or UnpinColumn methods of the IgcTreeGridComponent to pin or unpin columns by their field name:
this.treeGrid.pinColumn('Title');
this.treeGrid.unpinColumn('Name');
Ambos métodos devuelven un valor booleano que indica si su operación respectiva fue exitosa o no. Generalmente la razón por la que fallan es que la columna ya se encuentra en el estado deseado.
A column is pinned to the right of the rightmost pinned column. Changing the order of the pinned columns can be done by subscribing to the ColumnPin event and changing the InsertAtIndex property of the event arguments to the desired position index.
<igc-tree-grid id="dataGrid" auto-generate="true"></igc-tree-grid>
constructor() {
var dataGrid = document.getElementById('dataGrid') as IgcTreeGridComponent;
dataGrid.data = this.data;
dataGrid.addEventListener("columnPin", this.columnPinning);
}
public columnPinning(event) {
if (event.detail.column.field === 'Name') {
event.detail.insertAtIndex = 0;
}
}
Pinning Position
You can change the column pinning position via the Pinning configuration option. It allows you to set the columns position to either Start or End.
When set to End the columns are rendered at the end of the grid, after the unpinned columns. Unpinned columns can be scrolled horizontally, while the pinned columns remain fixed on the right.
<igc-tree-grid id="dataGrid" auto-generate="true"></igc-tree-grid>
var grid = document.getElementById('dataGrid') as IgcTreeGridComponent;
grid.pinning = { columns: ColumnPinningPosition.End };
Demo
Column Pinning on Both Sides
Además, puedes especificar cada ubicación de fijación de columna por separado, lo que te permite fijar columnas a ambos lados de la cuadrícula para mayor comodidad y optimización más sencilla de los conjuntos de datos. Por favor, consulta la demo a continuación para más referencias. Para fijar una columna, por favor selecciona una columna haciendo clic en un encabezado y utiliza los botones de fijar añadidos a la barra de herramientas, o simplemente arrastra una columna a otra fijada.
Custom Column Pinning UI
Puede definir su interfaz de usuario personalizada y cambiar el estado del pin de las columnas a través de la API relacionada.
Digamos que en lugar de una barra de herramientas le gustaría definir íconos de pin en los encabezados de las columnas en los que el usuario final puede hacer clic para cambiar el estado del pin de la columna en particular.
Esto se puede hacer creando una plantilla de encabezado para las columnas con un ícono personalizado.
<igc-tree-grid id="treeGrid" primary-key="ID" foreign-key="ParentID" auto-generate="false" width="100%" height="620px">
<igc-column id="Name" field="Name" data-type="String" width="250px"></igc-column>
<igc-column id="Title" field="Title" data-type="String" width="300px"></igc-column>
<igc-column id="ID" field="ID" data-type="Number" width="200px"></igc-column>
<igc-column id="HireDate" field="HireDate" header="Hire Date" data-type="Date" width="200px"></igc-column>
<igc-column id="Age" field="Age" data-type="Number" width="200px"></igc-column>
<igc-column id="Address" field="Address" data-type="String" width="200px"></igc-column>
<igc-column id="City" field="City" data-type="String" width="200px"></igc-column>
<igc-column id="Country" field="Country" data-type="String" width="200px"></igc-column>
<igc-column id="Fax" field="Fax" data-type="string" width="200px"></igc-column>
<igc-column id="PostalCode" field="PostalCode" header="Postal Code" data-type="String" width="200px"></igc-column>
<igc-column id="Phone" field="Phone" data-type="String" width="200px"></igc-column>
</igc-tree-grid>
constructor() {
var treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
var Name = document.getElementById('Name') as IgcColumnComponent;
var Title = document.getElementById('Title') as IgcColumnComponent;
var ID = document.getElementById('ID') as IgcColumnComponent;
var HireDate = document.getElementById('HireDate') as IgcColumnComponent;
var Age = document.getElementById('Age') as IgcColumnComponent;
var Address = document.getElementById('Address') as IgcColumnComponent;
var City = document.getElementById('City') as IgcColumnComponent;
var Country = document.getElementById('Country') as IgcColumnComponent;
var Fax = document.getElementById('Fax') as IgcColumnComponent;
var PostalCode = document.getElementById('PostalCode') as IgcColumnComponent;
var Phone = document.getElementById('Phone') as IgcColumnComponent;
treeGrid.data = this.data;
Name.headerTemplate = this.pinHeaderTemplate;
Title.headerTemplate = this.pinHeaderTemplate;
ID.headerTemplate = this.pinHeaderTemplate;
HireDate.headerTemplate = this.pinHeaderTemplate;
Age.headerTemplate = this.pinHeaderTemplate;
Address.headerTemplate = this.pinHeaderTemplate;
City.headerTemplate = this.pinHeaderTemplate;
Country.headerTemplate = this.pinHeaderTemplate;
Fax.headerTemplate = this.pinHeaderTemplate;
PostalCode.headerTemplate = this.pinHeaderTemplate;
Phone.headerTemplate = this.pinHeaderTemplate;
}
public pinHeaderTemplate = (ctx: IgcCellTemplateContext) => {
return html`
<div class="title-inner">
<span style="float:left">${ctx.cell.column.header}</span>
<igc-icon class="pin-icon" fontSet="fas" name="fa-thumbtack" @click="${() => toggleColumn(ctx.cell.column)}"></igx-icon>
</div>
`;
}
Al hacer clic en el icono personalizado, el estado del pin de la columna relacionada se puede cambiar utilizando los métodos API de la columna.
public toggleColumn(col: IgcColumnComponent) {
col.pinned ? col.unpin() : col.pin();
}
Demo
Pinning Limitations
- Setting column widths in percentage (%) explicitly makes the
IgcTreeGridComponentbody and header content to be misaligned when there are pinned columns. For column pinning to function correctly the column widths should be in pixels (px) or auto-assigned by theIgcTreeGridComponent.
Styling
In addition to the predefined themes, the grid could be further customized by setting some of the available CSS properties.
In case you would like to change some of the colors, you need to set an ID for the grid first:
<igc-tree-grid id="grid"></igc-tree-grid>
Luego establezca las propiedades CSS relacionadas con esta clase:
#grid {
--ig-grid-pinned-border-width: 5px;
--ig-grid-pinned-border-color: #FFCD0F;
--ig-grid-pinned-border-style: double;
--ig-grid-cell-active-border-color: #FFCD0F;
}
Demo
API References
Additional Resources
Nuestra comunidad es activa y siempre da la bienvenida a nuevas ideas.