Blazor Descripción general de la selección de cuadrícula
Con la función de selección de la Ignite UI for Blazor en Blazor Grid, puede interactuar fácilmente con los datos y manipularlos mediante interacciones simples con el mouse. Hay tres modos de selección disponibles:
Selección de fila
Selección de celda
Column selection
Con la propiedad RowSelection
, puede especificar:
Ninguno
Soltero
Selección múltiple
すぐに使用できる機能のフルセット は、ページング、ソート、フィルタリング、編集、グループ化から行と列の仮想化まで、あらゆる機能をカバーします。.NET 開発者には制限はありません。
Blazor Grid Selection Example
El siguiente ejemplo demuestra tres tipos de comportamientos de selección de celdas en IgbGrid
. Utilice los botones a continuación para habilitar cada uno de los modos de selección disponibles.
EXAMPLE
DATA
MODULES
RAZOR
CSS
using System;
using System.Collections.Generic;
public class NwindDataItem
{
public double ProductID { get ; set ; }
public string ProductName { get ; set ; }
public double SupplierID { get ; set ; }
public double CategoryID { get ; set ; }
public string QuantityPerUnit { get ; set ; }
public double UnitPrice { get ; set ; }
public double UnitsInStock { get ; set ; }
public double UnitsOnOrder { get ; set ; }
public double ReorderLevel { get ; set ; }
public bool Discontinued { get ; set ; }
public string OrderDate { get ; set ; }
public double Rating { get ; set ; }
public List<NwindDataItem_LocationsItem> Locations { get ; set ; }
}
public class NwindDataItem_LocationsItem
{
public string Shop { get ; set ; }
public string LastInventory { get ; set ; }
}
public class NwindData
: List <NwindDataItem >
{
public NwindData ( )
{
this .Add(new NwindDataItem()
{
ProductID = 1 ,
ProductName = @"Chai" ,
SupplierID = 1 ,
CategoryID = 1 ,
QuantityPerUnit = @"10 boxes x 20 bags" ,
UnitPrice = 18 ,
UnitsInStock = 39 ,
UnitsOnOrder = 30 ,
ReorderLevel = 10 ,
Discontinued = false ,
OrderDate = @"2012-02-12" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 2 ,
ProductName = @"Chang" ,
SupplierID = 1 ,
CategoryID = 1 ,
QuantityPerUnit = @"24 - 12 oz bottles" ,
UnitPrice = 19 ,
UnitsInStock = 17 ,
UnitsOnOrder = 40 ,
ReorderLevel = 25 ,
Discontinued = true ,
OrderDate = @"2003-03-17" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 3 ,
ProductName = @"Aniseed Syrup" ,
SupplierID = 1 ,
CategoryID = 2 ,
QuantityPerUnit = @"12 - 550 ml bottles" ,
UnitPrice = 10 ,
UnitsInStock = 13 ,
UnitsOnOrder = 70 ,
ReorderLevel = 25 ,
Discontinued = false ,
OrderDate = @"2006-03-17" ,
Rating = 3 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"24/7 Market" ,
LastInventory = @"2018-11-11"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 4 ,
ProductName = @"Chef Antons Cajun Seasoning" ,
SupplierID = 2 ,
CategoryID = 2 ,
QuantityPerUnit = @"48 - 6 oz jars" ,
UnitPrice = 22 ,
UnitsInStock = 53 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2016-03-17" ,
Rating = 3 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 5 ,
ProductName = @"Chef Antons Gumbo Mix" ,
SupplierID = 2 ,
CategoryID = 2 ,
QuantityPerUnit = @"36 boxes" ,
UnitPrice = 21.35 ,
UnitsInStock = 0 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = true ,
OrderDate = @"2011-11-11" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 6 ,
ProductName = @"Grandmas Boysenberry Spread" ,
SupplierID = 3 ,
CategoryID = 2 ,
QuantityPerUnit = @"12 - 8 oz jars" ,
UnitPrice = 25 ,
UnitsInStock = 0 ,
UnitsOnOrder = 30 ,
ReorderLevel = 25 ,
Discontinued = false ,
OrderDate = @"2017-12-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 7 ,
ProductName = @"Uncle Bobs Organic Dried Pears" ,
SupplierID = 3 ,
CategoryID = 7 ,
QuantityPerUnit = @"12 - 1 lb pkgs." ,
UnitPrice = 30 ,
UnitsInStock = 150 ,
UnitsOnOrder = 30 ,
ReorderLevel = 10 ,
Discontinued = false ,
OrderDate = @"2016-07-17" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 8 ,
ProductName = @"Northwoods Cranberry Sauce" ,
SupplierID = 3 ,
CategoryID = 2 ,
QuantityPerUnit = @"12 - 12 oz jars" ,
UnitPrice = 40 ,
UnitsInStock = 6 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2018-01-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 9 ,
ProductName = @"Mishi Kobe Niku" ,
SupplierID = 4 ,
CategoryID = 6 ,
QuantityPerUnit = @"18 - 500 g pkgs." ,
UnitPrice = 97 ,
UnitsInStock = 29 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = true ,
OrderDate = @"2010-02-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 10 ,
ProductName = @"Ikura" ,
SupplierID = 4 ,
CategoryID = 8 ,
QuantityPerUnit = @"12 - 200 ml jars" ,
UnitPrice = 31 ,
UnitsInStock = 31 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2008-05-17" ,
Rating = 3 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Wall Market" ,
LastInventory = @"2018-12-06"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 11 ,
ProductName = @"Queso Cabrales" ,
SupplierID = 5 ,
CategoryID = 4 ,
QuantityPerUnit = @"1 kg pkg." ,
UnitPrice = 21 ,
UnitsInStock = 22 ,
UnitsOnOrder = 30 ,
ReorderLevel = 30 ,
Discontinued = false ,
OrderDate = @"2009-01-17" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 12 ,
ProductName = @"Queso Manchego La Pastora" ,
SupplierID = 5 ,
CategoryID = 4 ,
QuantityPerUnit = @"10 - 500 g pkgs." ,
UnitPrice = 38 ,
UnitsInStock = 86 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2015-11-17" ,
Rating = 3 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 13 ,
ProductName = @"Konbu" ,
SupplierID = 6 ,
CategoryID = 8 ,
QuantityPerUnit = @"2 kg box" ,
UnitPrice = 6 ,
UnitsInStock = 24 ,
UnitsOnOrder = 30 ,
ReorderLevel = 5 ,
Discontinued = false ,
OrderDate = @"2015-03-17" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 14 ,
ProductName = @"Tofu" ,
SupplierID = 6 ,
CategoryID = 7 ,
QuantityPerUnit = @"40 - 100 g pkgs." ,
UnitPrice = 23.25 ,
UnitsInStock = 35 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2017-06-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 15 ,
ProductName = @"Genen Shouyu" ,
SupplierID = 6 ,
CategoryID = 2 ,
QuantityPerUnit = @"24 - 250 ml bottles" ,
UnitPrice = 15.5 ,
UnitsInStock = 39 ,
UnitsOnOrder = 30 ,
ReorderLevel = 5 ,
Discontinued = false ,
OrderDate = @"2014-03-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Local Market" ,
LastInventory = @"2018-07-03"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Wall Market" ,
LastInventory = @"2018-12-06"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 16 ,
ProductName = @"Pavlova" ,
SupplierID = 7 ,
CategoryID = 3 ,
QuantityPerUnit = @"32 - 500 g boxes" ,
UnitPrice = 17.45 ,
UnitsInStock = 29 ,
UnitsOnOrder = 30 ,
ReorderLevel = 10 ,
Discontinued = false ,
OrderDate = @"2018-03-28" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"24/7 Market" ,
LastInventory = @"2018-11-11"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 17 ,
ProductName = @"Alice Mutton" ,
SupplierID = 7 ,
CategoryID = 6 ,
QuantityPerUnit = @"20 - 1 kg tins" ,
UnitPrice = 39 ,
UnitsInStock = 0 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = true ,
OrderDate = @"2015-08-17" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 18 ,
ProductName = @"Carnarvon Tigers" ,
SupplierID = 7 ,
CategoryID = 8 ,
QuantityPerUnit = @"16 kg pkg." ,
UnitPrice = 62.5 ,
UnitsInStock = 42 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2005-09-27" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"24/7 Market" ,
LastInventory = @"2018-11-11"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 19 ,
ProductName = @"Teatime Chocolate Biscuits" ,
SupplierID = 8 ,
CategoryID = 3 ,
QuantityPerUnit = @"" ,
UnitPrice = 9.2 ,
UnitsInStock = 25 ,
UnitsOnOrder = 30 ,
ReorderLevel = 5 ,
Discontinued = false ,
OrderDate = @"2001-03-17" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Local Market" ,
LastInventory = @"2018-07-03"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 20 ,
ProductName = @"Sir Rodneys Marmalade" ,
SupplierID = 8 ,
CategoryID = 3 ,
QuantityPerUnit = @"4 - 100 ml jars" ,
UnitPrice = 4.5 ,
UnitsInStock = 40 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2005-03-17" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
}
}
cs コピー using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls;
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main (string [] args )
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app" );
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddIgniteUIBlazor(
typeof (IgbInputModule),
typeof (IgbPropertyEditorPanelModule),
typeof (IgbGridModule)
);
await builder.Build().RunAsync();
}
}
}
cs コピー
@using IgniteUI.Blazor.Controls
<div class ="container vertical ig-typography" >
<div class ="options vertical" >
<IgbPropertyEditorPanel
Name ="PropertyEditor"
@ref ="propertyEditor"
DescriptionType ="WebGrid"
IsHorizontal ="true"
IsWrappingEnabled ="true" >
<IgbPropertyEditorPropertyDescription
PropertyPath ="CellSelection"
Name ="CellSelectionEditor"
@ref ="cellSelectionEditor"
ValueType ="PropertyEditorValueType.EnumValue"
DropDownNames ="@( new string [] { "None" , "Single" , "Multiple" }) "
DropDownValues ="@( new string [] { "NOne" , "Single" , "Multiple" }) " >
</IgbPropertyEditorPropertyDescription >
</IgbPropertyEditorPanel >
</div >
<div class ="container vertical fill" >
<IgbGrid
AutoGenerate ="false"
Name ="grid"
@ref ="grid"
Data ="NwindData" >
<IgbColumn
Field ="ProductID"
Header ="Product ID" >
</IgbColumn >
<IgbColumn
Field ="ProductName"
Header ="Product Name" >
</IgbColumn >
<IgbColumn
Field ="UnitsInStock"
Header ="Units In Stock"
DataType ="GridColumnDataType.Number" >
</IgbColumn >
<IgbColumn
Field ="UnitPrice"
Header ="Units Price"
DataType ="GridColumnDataType.Number" >
</IgbColumn >
<IgbColumn
Field ="Discontinued"
DataType ="GridColumnDataType.Boolean" >
</IgbColumn >
<IgbColumn
Field ="OrderDate"
Header ="Order Date"
DataType ="GridColumnDataType.Date" >
</IgbColumn >
</IgbGrid >
</div >
</div >
@code {
private Action BindElements { get ; set ; }
protected override async Task OnAfterRenderAsync (bool firstRender )
{
var propertyEditor = this .propertyEditor;
var cellSelectionEditor = this .cellSelectionEditor;
var grid = this .grid;
this .BindElements = () => {
propertyEditor.Target = this .grid;
};
this .BindElements();
}
private IgbPropertyEditorPanel propertyEditor;
private IgbPropertyEditorPropertyDescription cellSelectionEditor;
private IgbGrid grid;
private NwindData _nwindData = null ;
public NwindData NwindData
{
get
{
if (_nwindData == null )
{
_nwindData = new NwindData();
}
return _nwindData;
}
}
}
razor コピー
Like this sample? Get access to our complete Ignite UI for Blazor toolkit and start building your own apps in minutes. Download it for free.
Blazor Grid Selection Options
El componente Ignite UI for Blazor IgbGrid
proporciona tres modos de selección diferentes: selección de filas , selección de celdas y selección de columnas . De forma predeterminada, solo el modo de selección de celdas múltiples está habilitado en el IgbGrid
. Para cambiar/habilitar el modo de selección, CellSelection
puede usar RowSelection
o Selectable
propiedades.
Blazor Grid Row Selection
La propiedad RowSelection
le permite especificar las siguientes opciones:
La selección None
fila estaría deshabilitada para IgbGrid
.
Single
: estará disponible la selección de solo una fila dentro de IgbGrid
.
Multiple
: la selección de varias filas estaría disponible usando los selectores de filas, con una combinación de teclas como Ctrl + clic , o presionando la tecla de espacio una vez que una celda está enfocada.
Vaya al tema Selección de filas para obtener más información.
Blazor Grid Cell Selection
La propiedad CellSelection
le permite especificar las siguientes opciones:
None
: la selección de celdas estaría deshabilitada para IgbGrid
.
Single
: estará disponible la selección de solo una celda dentro de IgbGrid
.
Multiple
: actualmente, este es el estado predeterminado de la selección en IgbGrid
. La selección de varias celdas está disponible arrastrando el mouse sobre las celdas, después de hacer clic continuamente con el botón izquierdo del mouse.
Vaya al tema Selección de celda para obtener más información.
Blazor Grid Column Selection
La propiedad Selectable
le permite especificar las siguientes opciones para cada IgbColumn
. La selección de columna correspondiente se habilitará o deshabilitará si esta propiedad se establece en verdadero o falso, respectivamente.
Esto lleva a las siguientes tres variaciones:
Selección única: haga clic con el mouse sobre la celda de la columna.
Selección de varias columnas: mantenga presionado Ctrl + clic del mouse sobre las celdas de la columna.
Selección de columnas de rango: mantener presionada la tecla Mayús + clic del mouse selecciona todo lo que se encuentra en el medio.
Vaya al tema Selección de columnas para obtener más información.
Usando el evento ContextMenu
puedes agregar un menú contextual personalizado para facilitar tu trabajo con IgbGrid
. Con un clic derecho en el cuerpo de la grilla, el evento emite la celda en la que se activa. El menú contextual funcionará con la celda emitida.
Si hay una selección multicelda , pondremos lógica, que comprobará si la celda seleccionada está en el área de selección multicelda. Si es así, también emitiremos los valores de las celdas seleccionadas.
Básicamente la función principal se verá así:
public void RightClick(MouseEventArgs e)
{
this.MenuX = e.ClientX + "px";
this.MenuY = e.ClientY + "px";
}
public void onMenuShow(IgbGridCellEventArgs e)
{
IgbGridCellEventArgsDetail detail = e.Detail;
this.ShowMenu = true;
this.ClickedCell = detail.Cell;
}
razor
El menú contextual tendrá las siguientes funciones:
Copia el valor de la celda seleccionada.
Copie el dataRow de la celda seleccionada.
Si la celda seleccionada está dentro de un rango de selección de varias celdas , copie todos los datos seleccionados .
public void CopyCellData()
{
this.ShowMenu = false;
this.SelectedData = this.ClickedCell.Value.ToString();
StateHasChanged();
}
public async void CopyRowData()
{
this.ShowMenu = false;
NwindDataItem rowData = this.NwindData.ElementAt(this.ClickedCell.Id.RowIndex);
this.SelectedData = JsonConvert.SerializeObject(rowData);
StateHasChanged();
}
public async void CopyCellsData()
{
this.ShowMenu = false;
var selectedData = await this.grid.GetSelectedDataAsync(true, false);
this.SelectedData = JsonConvert.SerializeObject(selectedData);
StateHasChanged();
}
razor
IgbGrid
buscará los datos copiados y los pegará en un elemento contenedor.
La plantilla que vamos a utilizar para combinar la grilla con el menú contextual:
<div class ="container vertical" >
<div class ="wrapper" oncontextmenu ="event.preventDefault()" >
<IgbGrid AutoGenerate ="false"
CellSelection ="GridSelectionMode.Multiple"
ContextMenu ="onMenuShow"
@oncontextmenu ="RightClick"
Name ="grid"
@ref ="grid"
Data ="NwindData" >
<IgbColumn Field ="ProductID"
Header ="Product ID" >
</IgbColumn >
<IgbColumn Field ="ProductName"
Header ="Product Name" >
</IgbColumn >
<IgbColumn Field ="UnitsInStock"
Header ="Units In Stock"
DataType ="GridColumnDataType.Number" >
</IgbColumn >
<IgbColumn Field ="UnitPrice"
Header ="Units Price"
DataType ="GridColumnDataType.Number" >
</IgbColumn >
<IgbColumn Field ="Discontinued"
DataType ="GridColumnDataType.Boolean" >
</IgbColumn >
<IgbColumn Field ="OrderDate"
Header ="Order Date"
DataType ="GridColumnDataType.Date" >
</IgbColumn >
</IgbGrid >
<div class ="selected-data-area" >
@ SelectedData
</div >
</div >
@ if (ShowMenu)
{
<div id ="menu" class ="contextmenu" style ="left: @ MenuX; top: @ MenuY " >
<span id ="copySingleCell" class ="item" @onclick ="CopyCellData" >
<IgbIcon @ref =icon IconName ="content_copy" Collection ="material" > </IgbIcon > Copy Cell Data
</span >
<span id ="copyRow" class ="item" @onclick ="CopyRowData" >
<IgbIcon IconName ="content_copy" Collection ="material" > </IgbIcon > Copy Row Data
</span >
<span id ="copyMultiCells" class ="item" @onclick ="CopyCellsData" >
<IgbIcon IconName ="content_copy" Collection ="material" > </IgbIcon > Copy Cells Data
</span >
</div >
}
</div >
razor
Seleccione varias celdas y presione el botón derecho del mouse. Aparecerá el menú contextual y después de seleccionar Copiar datos de celdas, los datos seleccionados aparecerán en el cuadro vacío de la derecha.
El resultado es:
EXAMPLE
DATA
MODULES
RAZOR
CSS
using System;
using System.Collections.Generic;
public class NwindDataItem
{
public double ProductID { get ; set ; }
public string ProductName { get ; set ; }
public double SupplierID { get ; set ; }
public double CategoryID { get ; set ; }
public string QuantityPerUnit { get ; set ; }
public double UnitPrice { get ; set ; }
public double UnitsInStock { get ; set ; }
public double UnitsOnOrder { get ; set ; }
public double ReorderLevel { get ; set ; }
public bool Discontinued { get ; set ; }
public string OrderDate { get ; set ; }
public double Rating { get ; set ; }
public List<NwindDataItem_LocationsItem> Locations { get ; set ; }
}
public class NwindDataItem_LocationsItem
{
public string Shop { get ; set ; }
public string LastInventory { get ; set ; }
}
public class NwindData
: List <NwindDataItem >
{
public NwindData ( )
{
this .Add(new NwindDataItem()
{
ProductID = 1 ,
ProductName = @"Chai" ,
SupplierID = 1 ,
CategoryID = 1 ,
QuantityPerUnit = @"10 boxes x 20 bags" ,
UnitPrice = 18 ,
UnitsInStock = 39 ,
UnitsOnOrder = 30 ,
ReorderLevel = 10 ,
Discontinued = false ,
OrderDate = @"2012-02-12" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 2 ,
ProductName = @"Chang" ,
SupplierID = 1 ,
CategoryID = 1 ,
QuantityPerUnit = @"24 - 12 oz bottles" ,
UnitPrice = 19 ,
UnitsInStock = 17 ,
UnitsOnOrder = 40 ,
ReorderLevel = 25 ,
Discontinued = true ,
OrderDate = @"2003-03-17" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 3 ,
ProductName = @"Aniseed Syrup" ,
SupplierID = 1 ,
CategoryID = 2 ,
QuantityPerUnit = @"12 - 550 ml bottles" ,
UnitPrice = 10 ,
UnitsInStock = 13 ,
UnitsOnOrder = 70 ,
ReorderLevel = 25 ,
Discontinued = false ,
OrderDate = @"2006-03-17" ,
Rating = 3 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"24/7 Market" ,
LastInventory = @"2018-11-11"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 4 ,
ProductName = @"Chef Antons Cajun Seasoning" ,
SupplierID = 2 ,
CategoryID = 2 ,
QuantityPerUnit = @"48 - 6 oz jars" ,
UnitPrice = 22 ,
UnitsInStock = 53 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2016-03-17" ,
Rating = 3 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 5 ,
ProductName = @"Chef Antons Gumbo Mix" ,
SupplierID = 2 ,
CategoryID = 2 ,
QuantityPerUnit = @"36 boxes" ,
UnitPrice = 21.35 ,
UnitsInStock = 0 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = true ,
OrderDate = @"2011-11-11" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 6 ,
ProductName = @"Grandmas Boysenberry Spread" ,
SupplierID = 3 ,
CategoryID = 2 ,
QuantityPerUnit = @"12 - 8 oz jars" ,
UnitPrice = 25 ,
UnitsInStock = 0 ,
UnitsOnOrder = 30 ,
ReorderLevel = 25 ,
Discontinued = false ,
OrderDate = @"2017-12-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 7 ,
ProductName = @"Uncle Bobs Organic Dried Pears" ,
SupplierID = 3 ,
CategoryID = 7 ,
QuantityPerUnit = @"12 - 1 lb pkgs." ,
UnitPrice = 30 ,
UnitsInStock = 150 ,
UnitsOnOrder = 30 ,
ReorderLevel = 10 ,
Discontinued = false ,
OrderDate = @"2016-07-17" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 8 ,
ProductName = @"Northwoods Cranberry Sauce" ,
SupplierID = 3 ,
CategoryID = 2 ,
QuantityPerUnit = @"12 - 12 oz jars" ,
UnitPrice = 40 ,
UnitsInStock = 6 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2018-01-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 9 ,
ProductName = @"Mishi Kobe Niku" ,
SupplierID = 4 ,
CategoryID = 6 ,
QuantityPerUnit = @"18 - 500 g pkgs." ,
UnitPrice = 97 ,
UnitsInStock = 29 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = true ,
OrderDate = @"2010-02-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 10 ,
ProductName = @"Ikura" ,
SupplierID = 4 ,
CategoryID = 8 ,
QuantityPerUnit = @"12 - 200 ml jars" ,
UnitPrice = 31 ,
UnitsInStock = 31 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2008-05-17" ,
Rating = 3 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Wall Market" ,
LastInventory = @"2018-12-06"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 11 ,
ProductName = @"Queso Cabrales" ,
SupplierID = 5 ,
CategoryID = 4 ,
QuantityPerUnit = @"1 kg pkg." ,
UnitPrice = 21 ,
UnitsInStock = 22 ,
UnitsOnOrder = 30 ,
ReorderLevel = 30 ,
Discontinued = false ,
OrderDate = @"2009-01-17" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Fun-Tasty Co." ,
LastInventory = @"2018-06-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 12 ,
ProductName = @"Queso Manchego La Pastora" ,
SupplierID = 5 ,
CategoryID = 4 ,
QuantityPerUnit = @"10 - 500 g pkgs." ,
UnitPrice = 38 ,
UnitsInStock = 86 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2015-11-17" ,
Rating = 3 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 13 ,
ProductName = @"Konbu" ,
SupplierID = 6 ,
CategoryID = 8 ,
QuantityPerUnit = @"2 kg box" ,
UnitPrice = 6 ,
UnitsInStock = 24 ,
UnitsOnOrder = 30 ,
ReorderLevel = 5 ,
Discontinued = false ,
OrderDate = @"2015-03-17" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 14 ,
ProductName = @"Tofu" ,
SupplierID = 6 ,
CategoryID = 7 ,
QuantityPerUnit = @"40 - 100 g pkgs." ,
UnitPrice = 23.25 ,
UnitsInStock = 35 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2017-06-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 15 ,
ProductName = @"Genen Shouyu" ,
SupplierID = 6 ,
CategoryID = 2 ,
QuantityPerUnit = @"24 - 250 ml bottles" ,
UnitPrice = 15.5 ,
UnitsInStock = 39 ,
UnitsOnOrder = 30 ,
ReorderLevel = 5 ,
Discontinued = false ,
OrderDate = @"2014-03-17" ,
Rating = 4 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Local Market" ,
LastInventory = @"2018-07-03"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Wall Market" ,
LastInventory = @"2018-12-06"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 16 ,
ProductName = @"Pavlova" ,
SupplierID = 7 ,
CategoryID = 3 ,
QuantityPerUnit = @"32 - 500 g boxes" ,
UnitPrice = 17.45 ,
UnitsInStock = 29 ,
UnitsOnOrder = 30 ,
ReorderLevel = 10 ,
Discontinued = false ,
OrderDate = @"2018-03-28" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Street Market" ,
LastInventory = @"2018-12-12"
},
new NwindDataItem_LocationsItem()
{
Shop = @"24/7 Market" ,
LastInventory = @"2018-11-11"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 17 ,
ProductName = @"Alice Mutton" ,
SupplierID = 7 ,
CategoryID = 6 ,
QuantityPerUnit = @"20 - 1 kg tins" ,
UnitPrice = 39 ,
UnitsInStock = 0 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = true ,
OrderDate = @"2015-08-17" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Farmer Market" ,
LastInventory = @"2018-04-04"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 18 ,
ProductName = @"Carnarvon Tigers" ,
SupplierID = 7 ,
CategoryID = 8 ,
QuantityPerUnit = @"16 kg pkg." ,
UnitPrice = 62.5 ,
UnitsInStock = 42 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2005-09-27" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"24/7 Market" ,
LastInventory = @"2018-11-11"
},
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 19 ,
ProductName = @"Teatime Chocolate Biscuits" ,
SupplierID = 8 ,
CategoryID = 3 ,
QuantityPerUnit = @"" ,
UnitPrice = 9.2 ,
UnitsInStock = 25 ,
UnitsOnOrder = 30 ,
ReorderLevel = 5 ,
Discontinued = false ,
OrderDate = @"2001-03-17" ,
Rating = 2 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Local Market" ,
LastInventory = @"2018-07-03"
}}
});
this .Add(new NwindDataItem()
{
ProductID = 20 ,
ProductName = @"Sir Rodneys Marmalade" ,
SupplierID = 8 ,
CategoryID = 3 ,
QuantityPerUnit = @"4 - 100 ml jars" ,
UnitPrice = 4.5 ,
UnitsInStock = 40 ,
UnitsOnOrder = 30 ,
ReorderLevel = 0 ,
Discontinued = false ,
OrderDate = @"2005-03-17" ,
Rating = 5 ,
Locations = new List<NwindDataItem_LocationsItem>()
{
new NwindDataItem_LocationsItem()
{
Shop = @"Super Market" ,
LastInventory = @"2018-09-09"
}}
});
}
}
cs コピー using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls;
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main (string [] args )
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app" );
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddIgniteUIBlazor(
typeof (IgbInputModule),
typeof (IgbGridModule),
typeof (IgbIconModule)
);
await builder.Build().RunAsync();
}
}
}
cs コピー
@using IgniteUI.Blazor.Controls
@using System.Text.Json
<div class ="container vertical" >
<div class ="wrapper" oncontextmenu ="event.preventDefault()" @onclick ="CloseMenu" >
<IgbGrid AutoGenerate ="false"
CellSelection ="GridSelectionMode.Multiple"
ContextMenu ="onMenuShow"
@oncontextmenu ="RightClick"
Name ="grid"
@ref ="grid"
Data ="NwindData" >
<IgbColumn Field ="ProductID"
Header ="Product ID" >
</IgbColumn >
<IgbColumn Field ="ProductName"
Header ="Product Name" >
</IgbColumn >
<IgbColumn Field ="UnitsInStock"
Header ="Units In Stock"
DataType ="GridColumnDataType.Number" >
</IgbColumn >
<IgbColumn Field ="UnitPrice"
Header ="Units Price"
DataType ="GridColumnDataType.Number" >
</IgbColumn >
<IgbColumn Field ="Discontinued"
DataType ="GridColumnDataType.Boolean" >
</IgbColumn >
<IgbColumn Field ="OrderDate"
Header ="Order Date"
DataType ="GridColumnDataType.Date" >
</IgbColumn >
</IgbGrid >
<div class ="selected-data-area" >
@ SelectedData
</div >
</div >
@ if (ShowMenu)
{
<div id ="menu" class ="contextmenu" style ="left: @ MenuX; top: @ MenuY " >
<span id ="copySingleCell" class ="item" @onclick ="CopyCellData" >
<IgbIcon @ref =icon IconName ="content_copy" Collection ="material" > </IgbIcon > Copy Cell Data
</span >
<span id ="copyRow" class ="item" @onclick ="CopyRowData" >
<IgbIcon IconName ="content_copy" Collection ="material" > </IgbIcon > Copy Row Data
</span >
<span id ="copyMultiCells" class ="item" @onclick ="CopyCellsData" >
<IgbIcon IconName ="content_copy" Collection ="material" > </IgbIcon > Copy Cells Data
</span >
</div >
}
</div >
<style >
.contextmenu {
position : absolute;
width : 180px ;
background : white;
display : flex;
cursor : context-menu;
flex-direction : column;
box-shadow : 0 1px 3px 0 rgba (0 , 0 , 0 , 0.2 ), 0 1px 1px 0 rgba (0 , 0 , 0 , 0.14 ), 0 2px 1px -1px rgba (0 , 0 , 0 , 0.12 );
z-index : 9999 ;
font-size : 0.75rem ;
font-weight : 650 ;
}
.item {
padding : 10px ;
display : flex;
}
.item :hover {
background : rgb (204 , 203 , 203 );
}
.icon {
vertical-align : middle;
margin-bottom : 5px ;
margin-right : 5px ;
}
.selected-data-area {
overflow-y : auto;
width : 50% ;
box-shadow : 0 1px 3px 0 rgba (0 , 0 , 0 , 0.2 ), 0 1px 1px 0 rgba (0 , 0 , 0 , 0.14 ), 0 2px 1px -1px rgba (0 , 0 , 0 , 0.12 );
margin-left : 10px ;
}
.wrapper {
margin : 10px ;
display : flex;
justify-content : space-evenly;
}
</style >
@code {
private IgbGrid grid;
public IgbIcon icon;
public bool ShowMenu = false ;
public bool ? ShowCopyCells = false ;
public string MenuX;
public string MenuY;
public IgbCellType ClickedCell;
public IgbRowType ClickedRow;
public string iconContent = " <svg xmlns ='http://www.w3.org/2000/svg' height ='48' viewBox ='0 -960 960 960' width ='48' > <path d = 'M180-81q-24 0-42-18t-18-42v-603h60v603h474v60H180Zm120-120q-24 0-42-18t-18-42v-560q0-24 18-42t42-18h440q24 0 42 18t18 42v560q0 24-18 42t-42 18H300Zm0-60h440v-560H300v560Zm0 0v-560 560Z' /> </svg > " ;
public string SelectedData;
private NwindData _nwindData = null ;
public NwindData NwindData
{
get
{
if (_nwindData == null )
{
_nwindData = new NwindData();
}
return _nwindData;
}
}
protected override void OnAfterRender (bool firstRender )
{
if (this .icon != null )
{
this .icon.EnsureReady().ContinueWith(new Action<Task>((e) =>
{
this .icon.RegisterIconFromTextAsync("content_copy" , iconContent, "material" );
}));
}
}
public void RightClick (MouseEventArgs e )
{
this .MenuX = e.ClientX + "px" ;
this .MenuY = e.ClientY + "px" ;
}
public void CloseMenu (MouseEventArgs e )
{
if (e.Button == 0 )
{
this .ShowMenu = false ;
StateHasChanged();
}
}
public async void onMenuShow (IgbGridContextMenuEventArgs e )
{
this .ShowMenu = true ;
this .ClickedCell = e.Detail.Cell;
this .ClickedRow = e.Detail.Row;
}
public void CopyCellData ( )
{
this .ShowMenu = false ;
this .SelectedData = this .ClickedCell.Value.ToString();
StateHasChanged();
}
public async void CopyRowData ( )
{
this .ShowMenu = false ;
this .SelectedData = JsonSerializer.Serialize(this .ClickedRow.Data);
StateHasChanged();
}
public async void CopyCellsData ( )
{
this .ShowMenu = false ;
var selectedData = await this .grid.GetSelectedDataAsync(false , false );
List<object > newList = new List<object >();
foreach (Dictionary < string , object > item in selectedData)
{
Dictionary<string , string > values = new Dictionary<string , string >();
foreach (var key in item.Keys)
{
object value = item[key];
string rawText = ((System.Text.Json.JsonElement)value ).GetRawText().Trim('"' );
values.Add(key, rawText);
}
newList.Add(values);
}
this .SelectedData = JsonSerializer.Serialize(newList);
StateHasChanged();
}
}
razor コピー
Known Issues and Limitations
Cuando la grilla no tiene PrimaryKey
configurada y los escenarios de datos remotos están habilitados (al paginar, ordenar, filtrar y desplazar solicitudes de activación a un servidor remoto para recuperar los datos que se mostrarán en la grilla), una fila perderá el siguiente estado después de un dato. solicitud completa:
Selección de fila
Fila Expandir/contraer
Edición de filas
Fijación de filas
API References
Additional Resources
Nuestra comunidad es activa y siempre da la bienvenida a nuevas ideas.