React Grid 列選択の概要
Ignite UI for React Data Grid は、IgrDataGridToolbar
コンポーネントまたはページのどこにでも配置できる columnChooser
コンポーネントによって UI から列の表示/非表示を行う機能をサポートしています。列の IsHidden
プロパティにより、手動生成の列に対してプログラムによって列の表示/非表示を設定することができます。IsHidden
の値は columnChooser
コンポーネントに反映されます。各方法は列の表示状態を変更するために使用できます。
React Grid 列選択の例
export class DataGridSharedData {
public static getEmployees(count?: number): any[] {
if (count === undefined) {
count = 250;
}
const employees: any[] = [];
let maleCount: number = 0;
let femaleCount: number = 0;
for (let i = 0; i < count; i++) {
const age: number = Math.round(this.getRandomNumber(20, 40));
const gender: string = this.getRandomGender();
const firstName: string = this.getRandomNameFirst(gender);
const lastName: string = this.getRandomNameLast();
const street: string = this.getRandomStreet();
const country: string = this.getRandomItem(this.countries);
const city: string = this.getRandomCity(country);
const generation = Math.floor(age / 10) * 10 + "s";
const email: string = firstName.toLowerCase() + "@" + this.getRandomItem(this.emails);
const website: string = firstName.toLowerCase() + "-" + this.getRandomItem(this.websites);
let photoPath: any;
if (gender === "male") {
maleCount++;
if (maleCount > 26) {
maleCount = 1;
}
photoPath = this.getPhotoMale(maleCount);
}
else {
femaleCount++;
if (femaleCount > 24) {
femaleCount = 1;
}
photoPath = this.getPhotoFemale(femaleCount);
}
let person: any = {};
person.Address = street + "," + city;
person.Age = age;
person.Birthday = this.getBirthday(age);
person.City = city;
person.Country = country;
person.CountryFlag = this.getCountryFlag(country);
person.Email = email;
person.FirstName = firstName;
person.Gender = this.getGenderPhoto(gender);
person.Generation = generation;
person.ID = this.pad(i + 1, 5);
person.LastName = lastName;
person.Name = firstName + " " + lastName;
person.Phone = this.getRandomPhone();
person.Photo = photoPath;
person.Street = street;
person.Salary = this.getRandomNumber(40, 200) * 1000;
person.Sales = this.getRandomNumber(200, 980) * 1000;
person.Website = website;
person.Productivity = this.getProductivity();
if (person.Salary < 50000) {
person.Income = "Low";
} else if (person.Salary < 100000) {
person.Income = "Average";
} else {
person.Income = "High";
}
employees.push(person);
}
return employees;
}
public static getProductivity(weekCount?: number): any[] {
if (weekCount === undefined) {
weekCount = 52;
}
const productivity: any[] = [];
for (let w = 0; w < weekCount; w++) {
const value = this.getRandomNumber(-50, 50);
productivity.push({Value: value, Week: w});
}
return productivity;
}
public static getSales(count?: number): any[] {
if (count === undefined) {
count = 250;
}
const names: string[] = [
"Intel CPU", "AMD CPU",
"Intel Motherboard", "AMD Motherboard", "NVIDIA Motherboard",
"NVIDIA GPU", "GIGABYTE GPU", "Asus GPU", "AMD GPU", "MSI GPU",
"Corsair Memory", "Patriot Memory", "Skill Memory",
"Samsung HDD", "WD HDD", "Seagate HDD", "Intel HDD",
"Samsung SSD", "WD SSD", "Seagate SSD", "Intel SSD",
"Samsung Monitor", "Asus Monitor", "LG Monitor", "HP Monitor" ];
const countries: string[] = ["USA", "UK", "France", "Canada", "Poland", "Japan", "Germany"];
const status: string[] = ["Packing", "Shipped", "Delivered"];
const sales: any[] = [];
for (let i = 0; i < count; i++) {
const price = this.getRandomNumber(100, 900);
const items = this.getRandomNumber(10, 80);
const value = price * items;
const margin = this.getRandomNumber(3, 10);
const profit = Math.round((price * margin / 100) * items);
const country = this.getRandomItem(countries);
sales.push({
BundlePrice: price,
ProductPrice: price,
Margin: margin,
OrderDate: this.getRandomDate(new Date(2012, 0, 1), new Date()),
OrderItems: items,
OrderValue: value, // Math.round(value / 1000) + "," + Math.round(value % 1000),
ProductID: 1001 + i,
ProductName: this.getRandomItem(names),
Profit: profit,
Countries: country,
CountryFlag: this.getCountryFlag(country),
Status: this.getRandomItem(status)
});
}
return sales;
}
public static getHouses(count?: number): any[] {
if (count === undefined) {
count = 250;
}
const houses: any[] = [];
const property: string[] = [ "Townhouse", "Single", "Condo", "Villa"];
const emails: string[] = [ "estates.com", "remax.com", "zillow.com", "realtor.com", "coldwell.com"];
const countries: string[] = ["USA", "UK", "France", "Canada", "Poland", "Japan", "Germany"];
for (let i = 0; i < count; i++) {
const year: number = this.getRandomNumber(1950, 2015);
const age: number = 2020 - year;
const gender: string = this.getRandomGender();
const firstName: string = this.getRandomNameFirst(gender);
const lastName: string = this.getRandomNameLast();
const initials = firstName.substr(0, 1).toLowerCase();
const email: string = initials + lastName.toLowerCase() + "@" + this.getRandomItem(emails);
const street: string = this.getRandomStreet();
const country: string = this.getRandomItem(countries);
const city: string = this.getRandomCity(country);
houses.push({
Address: street + "," + city,
Age: age,
Agent: firstName + " " + lastName,
Area: this.getRandomNumber(50, 300),
Baths: this.getRandomNumber(1, 3),
Built: year,
City: city,
Country: country,
CountryFlag: this.getCountryFlag(country),
Email: email,
ID: this.pad(i + 1, 5),
Phone: this.getRandomPhone(),
Price: this.getRandomNumber(210, 900) * 1000,
Property: this.getRandomItem(property),
Rooms: this.getRandomNumber(2, 5),
SaleDate: this.getRandomDate(new Date(2015, 0, 1), new Date()),
Street: street,
});
}
return houses;
}
private static websites: string[] = [ ".com", ".gov", ".edu", ".org"];
private static emails: string[] = [ "gmail.com", "yahoo.com", "twitter.com"];
private static genders: string[] = ["male", "female"];
private static maleNames: string[] = ["Kyle", "Oscar", "Ralph", "Mike", "Bill", "Frank", "Howard", "Jack", "Larry", "Pete", "Steve", "Vince", "Mark", "Alex", "Max", "Brian", "Chris", "Andrew", "Martin", "Mike", "Steve", "Glenn", "Bruce"];
private static femaleNames: string[] = ["Gina", "Irene", "Katie", "Brenda", "Casey", "Fiona", "Holly", "Kate", "Liz", "Pamela", "Nelly", "Marisa", "Monica", "Anna", "Jessica", "Sofia", "Isabella", "Margo", "Jane", "Audrey", "Sally", "Melanie", "Greta", "Aurora", "Sally"];
private static lastNames: string[] = ["Adams", "Crowley", "Ellis", "Martinez", "Irvine", "Maxwell", "Clark", "Owens", "Rooney", "Lincoln", "Thomas", "Spacey", "MOrgan", "King", "Newton", "Fitzgerald", "Holmes", "Jefferson", "Landry", "Berry", "Perez", "Spencer", "Starr", "Carter", "Edwards", "Stark", "Johnson", "Fitz", "Chief", "Blanc", "Perry", "Stone", "Williams", "Lane", "Jobs", "Adams", "Power", "Tesla"];
private static countries: string[] = ["USA", "UK", "France", "Canada", "Poland"];
private static citiesUS: string[] = ["New York", "Los Angeles", "Miami", "San Francisco", "San Diego", "Las Vegas"];
private static citiesUK: string[] = ["London", "Liverpool", "Manchester"];
private static citiesFR: string[] = ["Paris", "Marseille", "Lyon"];
private static citiesCA: string[] = ["Toronto", "Vancouver", "Montreal"];
private static citiesPL: string[] = ["Krakow", "Warsaw", "Wroclaw", "Gdansk"];
private static citiesJP: string[] = ["Tokyo", "Osaka", "Kyoto", "Yokohama"];
private static citiesGR: string[] = ["Berlin", "Bonn", "Cologne", "Munich", "Hamburg"];
private static roadSuffixes: string[] = ["Road", "Street", "Way"];
private static roadNames: string[] = ["Main", "Garden", "Broad", "Oak", "Cedar", "Park", "Pine", "Elm", "Market", "Hill"];
private static getRandomNumber(min: number, max: number): number {
return Math.round(min + Math.random() * (max - min));
}
private static getRandomItem(array: any[]): any {
const index = Math.round(this.getRandomNumber(0, array.length - 1));
return array[index];
}
private static getRandomDate(start: Date, end: Date): Date {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
private static getRandomPhone(): string {
const phoneCode = this.getRandomNumber(100, 900);
const phoneNum1 = this.getRandomNumber(100, 900);
const phoneNum2 = this.getRandomNumber(1000, 9000);
const phone = phoneCode + "-" + phoneNum1 + "-" + phoneNum2;
return phone;
}
private static getRandomGender(): string {
return this.getRandomItem(this.genders);
}
private static getRandomNameLast(): string {
return this.getRandomItem(this.lastNames);
}
private static getRandomNameFirst(gender: string): string {
if (gender === "male") {
return this.getRandomItem(this.maleNames);
}
else {
return this.getRandomItem(this.femaleNames);
}
}
private static getRandomCity(country: string): string {
if (country === "Canada") {
return this.getRandomItem(this.citiesCA);
} else if (country === "France") {
return this.getRandomItem(this.citiesFR);
} else if (country === "Poland") {
return this.getRandomItem(this.citiesPL);
} else if (country === "USA") {
return this.getRandomItem(this.citiesUS);
} else if (country === "Japan") {
return this.getRandomItem(this.citiesJP);
} else if (country === "Germany") {
return this.getRandomItem(this.citiesGR);
} else { // if (country === "United Kingdom") {
return this.getRandomItem(this.citiesUK);
}
}
private static getRandomStreet(): string {
const num = Math.round(this.getRandomNumber(100, 300)).toString();
const road = this.getRandomItem(this.roadNames);
const suffix = this.getRandomItem(this.roadSuffixes);
return num + " " + road + " " + suffix;
}
private static getBirthday(age: number): Date {
const today: Date = new Date();
const year: number = today.getFullYear() - age;
const month: number = this.getRandomNumber(0, 8);
const day: number = this.getRandomNumber(10, 27);
return new Date(year, month, day);
}
private static getPhotoMale(id: number): string {
return 'https://static.infragistics.com/xplatform/images/people//GUY' + this.pad(id, 2) + '.png';
}
private static getPhotoFemale(id: number): string {
return 'https://static.infragistics.com/xplatform/images/people/GIRL' + this.pad(id, 2) + '.png';
}
private static getGenderPhoto(gender: string): string {
return 'https://static.infragistics.com/xplatform/images/genders/' + gender + '.png';
}
private static getCountryFlag(country: string): string {
return 'https://static.infragistics.com/xplatform/images/flags/' + country + '.png';
}
private static pad(num: number, size: number): string{
let s = num + "";
while (s.length < size) {
s = "0" + s;
}
return s;
}
}
tsimport React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { DataGridSharedData } from "./DataGridSharedData";
import { IgrImageColumn } from "@infragistics/igniteui-react-grids";
import { IgrTextColumn } from "@infragistics/igniteui-react-grids";
import { IgrNumericColumn } from "@infragistics/igniteui-react-grids";
import { IgrDateTimeColumn } from "@infragistics/igniteui-react-grids";
import { IgrDataGridModule } from "@infragistics/igniteui-react-grids";
import { IgrDataGrid } from "@infragistics/igniteui-react-grids";
import { IgrDataGridToolbarModule } from "@infragistics/igniteui-react-grids";
import { IgrDataGridToolbar } from "@infragistics/igniteui-react-grids";
import { IgrGridColumnOptionsModule } from "@infragistics/igniteui-react-grids";
IgrDataGridModule.register();
IgrDataGridToolbarModule.register();
IgrGridColumnOptionsModule.register();
export default class DataGridColumnChooserToolbar extends React.Component<any, any> {
public data: any[];
public grid: IgrDataGrid;
public toolbar: IgrDataGridToolbar;
constructor(props: any) {
super(props);
this.state = { componentVisible: true };
this.data = DataGridSharedData.getSales();
}
public onGridRef = (grid: IgrDataGrid) => {
this.grid = grid;
if (this.toolbar) {
this.toolbar.targetGrid = this.grid;
}
}
public onToolbarRef = (toolbar: IgrDataGridToolbar) => {
this.toolbar = toolbar;
if (this.toolbar) {
this.toolbar.targetGrid = this.grid;
}
}
public render(): JSX.Element {
return (
<div className="container sample">
<IgrDataGridToolbar
ref={this.onToolbarRef}
toolbarTitle="Global Sales"
columnChooser="true"
/>
<IgrDataGrid
ref={this.onGridRef}
height="calc(100% - 2rem)"
width="100%"
autoGenerateColumns="false"
cornerRadiusTopLeft="0"
cornerRadiusTopRight="0"
isColumnOptionsEnabled="true"
dataSource={this.data}
>
<IgrTextColumn
field="ProductID"
headerText="ID"
width="*>110"
horizontalAlignment="center"
isHidden="true"
/>
<IgrTextColumn
field="ProductName"
headerText="Product"
isHidden="true"
width="*>140"
/>
<IgrImageColumn
field="CountryFlag"
headerText="Country"
width="*>140"
contentOpacity="1"
horizontalAlignment="center"
paddingTop="5" paddingBottom="5"
/>
<IgrNumericColumn
field="ProductPrice"
headerText="Price"
width="*>100"
positivePrefix="$"
showGroupingSeparator="true"
minFractionDigits={2}
isHidden="true"
/>
<IgrNumericColumn
field="OrderItems"
headerText="Orders"
width="*>90"
/>
<IgrNumericColumn
field="OrderValue"
headerText="Order Value"
width="*>140"
positivePrefix="$"
showGroupingSeparator="true"
/>
<IgrDateTimeColumn
field="OrderDate"
headerText="Order Date"
width="*>140"
horizontalAlignment="right"
dateTimeFormat="DateShort"
/>
<IgrNumericColumn
field="Margin"
headerText="Margin"
width="*>120"
positiveSuffix="%"
horizontalAlignment="center"
/>
<IgrNumericColumn
field="Profit"
headerText="Profit"
width="*>120"
positivePrefix="$"
showGroupingSeparator="true"
/>
<IgrTextColumn
field="Status"
headerText="Status"
width="*>120"
horizontalAlignment="center"
/>
</IgrDataGrid>
</div>
);
}
}
// rendering above class to the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<DataGridColumnChooserToolbar/>);
tsx
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
ツールバーの列選択 UI
列選択 UI は、グリッドとは別に IgrDataGridToolbar
コンポーネント内でアクセスできます。このため、ツールバーの columnChooser
プロパティを true に設定します。
ツールバーは IgrButton
を表示し、クリックすると列選択 UI を表示します。このボタンは、非表示列の合計も表示します。ツールバーが作成されていない場合、IgrColumnChooser
プロパティを有効にしても効果はなく、ボタンを非表示にします。
IgrDataGridToolbar
は、toolbarTitle
プロパティを使用してツールバーにタイトルを追加、columnChooserText
プロパティを設定して IgrButton
にテキストを配置、ColumnChooserTitle
を設定して、タイトル ヘッダーを列選択 UI に追加などの追加プロパティを提供します。
列選択は、グリッドの columnHidingAnimationMode
および columnShowingAnimationMode
プロパティを設定することでアニメーションで構成できます。
コード スニペット
以下は、データ グリッドの列選択ツールバー UI の実装方法を示します。
<IgrDataGridToolbar ref={this.onToolbarRef}
toolbarTitle="Grid Title"
columnChooser="true"
columnChooserText="Columns"
columnChooserTitle="Column Chooser">
</IgrDataGridToolbar>
<IgrDataGrid
ref={this.onGridRef}
height="calc(100% - 40px)"
dataSource={this.data}
autoGenerateColumns="true"
columnHidingAnimationMode="SlideOver">
</IgrDataGrid>
tsx
import { IgrDataGrid } from 'igniteui-react-grids';
import { IgrDataGridToolbar } from 'igniteui-react-grids';
public grid : IgrDataGrid;
public toolbar: IgrDataGridToolbar;
this.onGridRef = this.onGridRef.bind(this);
this.onToolbarRef = this.onToolbarRef.bind(this);
public onGridRef(grid: IgrDataGrid) {
this.grid = grid;
if (this.toolbar != null) {
this.toolbar.targetGrid = this.grid;
this.grid.columnMovingAnimationMode = ColumnMovingAnimationMode.SlideOver;
let productNameColumn = document.getElementById("productname") as IgrTextColumnComponent;
productNameColumn.isHidden = true;
}
}
public onToolbarRef(toolbar: IgrDataGridToolbar) {
this.toolbar = toolbar;
if (this.grid != null) {
this.toolbar.targetGrid = this.grid;
this.toolbar.columnChooser = "true";
this.toolbar.toolbarTitle = "Grid Title";
this.toolbar.columnChooserText = "Column Chooser";
this.toolbar.columnChooserTitle = "Column Chooser";
}
}
ts
シンプルな列選択
ツールバーなしで IgrColumnChooser
UIを手動で表示し、ページの任意の場所に配置するとします。マークアップでコンポーネントのインスタンスを作成して簡単に行うことができます。
サンプル
export class DataGridSharedData {
public static getEmployees(count?: number): any[] {
if (count === undefined) {
count = 250;
}
const employees: any[] = [];
let maleCount: number = 0;
let femaleCount: number = 0;
for (let i = 0; i < count; i++) {
const age: number = Math.round(this.getRandomNumber(20, 40));
const gender: string = this.getRandomGender();
const firstName: string = this.getRandomNameFirst(gender);
const lastName: string = this.getRandomNameLast();
const street: string = this.getRandomStreet();
const country: string = this.getRandomItem(this.countries);
const city: string = this.getRandomCity(country);
const generation = Math.floor(age / 10) * 10 + "s";
const email: string = firstName.toLowerCase() + "@" + this.getRandomItem(this.emails);
const website: string = firstName.toLowerCase() + "-" + this.getRandomItem(this.websites);
let photoPath: any;
if (gender === "male") {
maleCount++;
if (maleCount > 26) {
maleCount = 1;
}
photoPath = this.getPhotoMale(maleCount);
}
else {
femaleCount++;
if (femaleCount > 24) {
femaleCount = 1;
}
photoPath = this.getPhotoFemale(femaleCount);
}
let person: any = {};
person.Address = street + "," + city;
person.Age = age;
person.Birthday = this.getBirthday(age);
person.City = city;
person.Country = country;
person.CountryFlag = this.getCountryFlag(country);
person.Email = email;
person.FirstName = firstName;
person.Gender = this.getGenderPhoto(gender);
person.Generation = generation;
person.ID = this.pad(i + 1, 5);
person.LastName = lastName;
person.Name = firstName + " " + lastName;
person.Phone = this.getRandomPhone();
person.Photo = photoPath;
person.Street = street;
person.Salary = this.getRandomNumber(40, 200) * 1000;
person.Sales = this.getRandomNumber(200, 980) * 1000;
person.Website = website;
person.Productivity = this.getProductivity();
if (person.Salary < 50000) {
person.Income = "Low";
} else if (person.Salary < 100000) {
person.Income = "Average";
} else {
person.Income = "High";
}
employees.push(person);
}
return employees;
}
public static getProductivity(weekCount?: number): any[] {
if (weekCount === undefined) {
weekCount = 52;
}
const productivity: any[] = [];
for (let w = 0; w < weekCount; w++) {
const value = this.getRandomNumber(-50, 50);
productivity.push({Value: value, Week: w});
}
return productivity;
}
public static getSales(count?: number): any[] {
if (count === undefined) {
count = 250;
}
const names: string[] = [
"Intel CPU", "AMD CPU",
"Intel Motherboard", "AMD Motherboard", "NVIDIA Motherboard",
"NVIDIA GPU", "GIGABYTE GPU", "Asus GPU", "AMD GPU", "MSI GPU",
"Corsair Memory", "Patriot Memory", "Skill Memory",
"Samsung HDD", "WD HDD", "Seagate HDD", "Intel HDD",
"Samsung SSD", "WD SSD", "Seagate SSD", "Intel SSD",
"Samsung Monitor", "Asus Monitor", "LG Monitor", "HP Monitor" ];
const countries: string[] = ["USA", "UK", "France", "Canada", "Poland", "Japan", "Germany"];
const status: string[] = ["Packing", "Shipped", "Delivered"];
const sales: any[] = [];
for (let i = 0; i < count; i++) {
const price = this.getRandomNumber(100, 900);
const items = this.getRandomNumber(10, 80);
const value = price * items;
const margin = this.getRandomNumber(3, 10);
const profit = Math.round((price * margin / 100) * items);
const country = this.getRandomItem(countries);
sales.push({
BundlePrice: price,
ProductPrice: price,
Margin: margin,
OrderDate: this.getRandomDate(new Date(2012, 0, 1), new Date()),
OrderItems: items,
OrderValue: value, // Math.round(value / 1000) + "," + Math.round(value % 1000),
ProductID: 1001 + i,
ProductName: this.getRandomItem(names),
Profit: profit,
Countries: country,
CountryFlag: this.getCountryFlag(country),
Status: this.getRandomItem(status)
});
}
return sales;
}
public static getHouses(count?: number): any[] {
if (count === undefined) {
count = 250;
}
const houses: any[] = [];
const property: string[] = [ "Townhouse", "Single", "Condo", "Villa"];
const emails: string[] = [ "estates.com", "remax.com", "zillow.com", "realtor.com", "coldwell.com"];
const countries: string[] = ["USA", "UK", "France", "Canada", "Poland", "Japan", "Germany"];
for (let i = 0; i < count; i++) {
const year: number = this.getRandomNumber(1950, 2015);
const age: number = 2020 - year;
const gender: string = this.getRandomGender();
const firstName: string = this.getRandomNameFirst(gender);
const lastName: string = this.getRandomNameLast();
const initials = firstName.substr(0, 1).toLowerCase();
const email: string = initials + lastName.toLowerCase() + "@" + this.getRandomItem(emails);
const street: string = this.getRandomStreet();
const country: string = this.getRandomItem(countries);
const city: string = this.getRandomCity(country);
houses.push({
Address: street + "," + city,
Age: age,
Agent: firstName + " " + lastName,
Area: this.getRandomNumber(50, 300),
Baths: this.getRandomNumber(1, 3),
Built: year,
City: city,
Country: country,
CountryFlag: this.getCountryFlag(country),
Email: email,
ID: this.pad(i + 1, 5),
Phone: this.getRandomPhone(),
Price: this.getRandomNumber(210, 900) * 1000,
Property: this.getRandomItem(property),
Rooms: this.getRandomNumber(2, 5),
SaleDate: this.getRandomDate(new Date(2015, 0, 1), new Date()),
Street: street,
});
}
return houses;
}
private static websites: string[] = [ ".com", ".gov", ".edu", ".org"];
private static emails: string[] = [ "gmail.com", "yahoo.com", "twitter.com"];
private static genders: string[] = ["male", "female"];
private static maleNames: string[] = ["Kyle", "Oscar", "Ralph", "Mike", "Bill", "Frank", "Howard", "Jack", "Larry", "Pete", "Steve", "Vince", "Mark", "Alex", "Max", "Brian", "Chris", "Andrew", "Martin", "Mike", "Steve", "Glenn", "Bruce"];
private static femaleNames: string[] = ["Gina", "Irene", "Katie", "Brenda", "Casey", "Fiona", "Holly", "Kate", "Liz", "Pamela", "Nelly", "Marisa", "Monica", "Anna", "Jessica", "Sofia", "Isabella", "Margo", "Jane", "Audrey", "Sally", "Melanie", "Greta", "Aurora", "Sally"];
private static lastNames: string[] = ["Adams", "Crowley", "Ellis", "Martinez", "Irvine", "Maxwell", "Clark", "Owens", "Rooney", "Lincoln", "Thomas", "Spacey", "MOrgan", "King", "Newton", "Fitzgerald", "Holmes", "Jefferson", "Landry", "Berry", "Perez", "Spencer", "Starr", "Carter", "Edwards", "Stark", "Johnson", "Fitz", "Chief", "Blanc", "Perry", "Stone", "Williams", "Lane", "Jobs", "Adams", "Power", "Tesla"];
private static countries: string[] = ["USA", "UK", "France", "Canada", "Poland"];
private static citiesUS: string[] = ["New York", "Los Angeles", "Miami", "San Francisco", "San Diego", "Las Vegas"];
private static citiesUK: string[] = ["London", "Liverpool", "Manchester"];
private static citiesFR: string[] = ["Paris", "Marseille", "Lyon"];
private static citiesCA: string[] = ["Toronto", "Vancouver", "Montreal"];
private static citiesPL: string[] = ["Krakow", "Warsaw", "Wroclaw", "Gdansk"];
private static citiesJP: string[] = ["Tokyo", "Osaka", "Kyoto", "Yokohama"];
private static citiesGR: string[] = ["Berlin", "Bonn", "Cologne", "Munich", "Hamburg"];
private static roadSuffixes: string[] = ["Road", "Street", "Way"];
private static roadNames: string[] = ["Main", "Garden", "Broad", "Oak", "Cedar", "Park", "Pine", "Elm", "Market", "Hill"];
private static getRandomNumber(min: number, max: number): number {
return Math.round(min + Math.random() * (max - min));
}
private static getRandomItem(array: any[]): any {
const index = Math.round(this.getRandomNumber(0, array.length - 1));
return array[index];
}
private static getRandomDate(start: Date, end: Date): Date {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
private static getRandomPhone(): string {
const phoneCode = this.getRandomNumber(100, 900);
const phoneNum1 = this.getRandomNumber(100, 900);
const phoneNum2 = this.getRandomNumber(1000, 9000);
const phone = phoneCode + "-" + phoneNum1 + "-" + phoneNum2;
return phone;
}
private static getRandomGender(): string {
return this.getRandomItem(this.genders);
}
private static getRandomNameLast(): string {
return this.getRandomItem(this.lastNames);
}
private static getRandomNameFirst(gender: string): string {
if (gender === "male") {
return this.getRandomItem(this.maleNames);
}
else {
return this.getRandomItem(this.femaleNames);
}
}
private static getRandomCity(country: string): string {
if (country === "Canada") {
return this.getRandomItem(this.citiesCA);
} else if (country === "France") {
return this.getRandomItem(this.citiesFR);
} else if (country === "Poland") {
return this.getRandomItem(this.citiesPL);
} else if (country === "USA") {
return this.getRandomItem(this.citiesUS);
} else if (country === "Japan") {
return this.getRandomItem(this.citiesJP);
} else if (country === "Germany") {
return this.getRandomItem(this.citiesGR);
} else { // if (country === "United Kingdom") {
return this.getRandomItem(this.citiesUK);
}
}
private static getRandomStreet(): string {
const num = Math.round(this.getRandomNumber(100, 300)).toString();
const road = this.getRandomItem(this.roadNames);
const suffix = this.getRandomItem(this.roadSuffixes);
return num + " " + road + " " + suffix;
}
private static getBirthday(age: number): Date {
const today: Date = new Date();
const year: number = today.getFullYear() - age;
const month: number = this.getRandomNumber(0, 8);
const day: number = this.getRandomNumber(10, 27);
return new Date(year, month, day);
}
private static getPhotoMale(id: number): string {
return 'https://static.infragistics.com/xplatform/images/people//GUY' + this.pad(id, 2) + '.png';
}
private static getPhotoFemale(id: number): string {
return 'https://static.infragistics.com/xplatform/images/people/GIRL' + this.pad(id, 2) + '.png';
}
private static getGenderPhoto(gender: string): string {
return 'https://static.infragistics.com/xplatform/images/genders/' + gender + '.png';
}
private static getCountryFlag(country: string): string {
return 'https://static.infragistics.com/xplatform/images/flags/' + country + '.png';
}
private static pad(num: number, size: number): string{
let s = num + "";
while (s.length < size) {
s = "0" + s;
}
return s;
}
}
tsimport React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { DataGridSharedData } from "./DataGridSharedData";
import { IgrImageColumn } from "@infragistics/igniteui-react-grids";
import { IgrTextColumn } from "@infragistics/igniteui-react-grids";
import { IgrNumericColumn } from "@infragistics/igniteui-react-grids";
import { IgrDateTimeColumn } from "@infragistics/igniteui-react-grids";
import { IgrDataGridModule } from "@infragistics/igniteui-react-grids";
import { IgrDataGrid } from "@infragistics/igniteui-react-grids";
import { IgrGridColumnOptionsModule } from "@infragistics/igniteui-react-grids";
import { IgrColumnChooserModule } from "@infragistics/igniteui-react-grids";
import { IgrColumnChooser } from "@infragistics/igniteui-react-grids";
IgrDataGridModule.register();
IgrColumnChooserModule.register();
IgrGridColumnOptionsModule.register();
export default class DataGridColumnChooserPicker extends React.Component<any, any> {
public data: any[];
public grid: IgrDataGrid;
public columnChooser: IgrColumnChooser;
constructor(props: any) {
super(props);
this.state = { componentVisible: true };
this.data = DataGridSharedData.getSales();
}
public onGridRef = (grid: IgrDataGrid) => {
this.grid = grid;
if (this.columnChooser) {
this.columnChooser.targetGrid = this.grid;
}
}
public onColumnChoosingRef = (columnChooser: IgrColumnChooser) => {
this.columnChooser = columnChooser;
if (this.columnChooser) {
this.columnChooser.targetGrid = this.grid;
}
}
public render(): JSX.Element {
return (
<div className="container horizontal">
<div className="container" style={{marginLeft: "0.4rem", marginTop: "2px", marginRight: "0.5rem", marginBottom: "0.25rem", padding: "0.5rem", background: "rgb(248, 248, 248)", borderRadius: "10px, box-shadow: 1px 1px 2px 2px rgb(50 50 50 / 25%)"}} >
<IgrColumnChooser
ref={this.onColumnChoosingRef}
height="100%"
width="200px"
title="Column Chooser">
</IgrColumnChooser>
</div>
<div className="container">
<IgrDataGrid
ref={this.onGridRef}
height="100%"
width="100%"
autoGenerateColumns="false"
isColumnOptionsEnabled="true"
dataSource={this.data}
>
<IgrTextColumn
field="ProductID"
headerText="ID"
width="*>90"
horizontalAlignment="center"
/>
<IgrTextColumn
field="ProductName"
headerText="Product" width="*>100"
/>
<IgrImageColumn
field="CountryFlag"
headerText="Country"
width="*>120"
contentOpacity="1"
horizontalAlignment="center"
paddingTop="5" paddingBottom="5"
/>
<IgrNumericColumn
field="ProductPrice"
headerText="Price"
width="*>110"
positivePrefix="$"
showGroupingSeparator="true"
minFractionDigits={2}
/>
<IgrNumericColumn
field="OrderItems"
headerText="Orders"
width="*>100"
/>
<IgrNumericColumn
field="OrderValue"
headerText="Order Value"
width="*>140"
positivePrefix="$"
showGroupingSeparator="true"
/>
<IgrDateTimeColumn
field="OrderDate"
headerText="Order Date"
width="*>130"
horizontalAlignment="right"
dateTimeFormat="DateShort"
/>
<IgrNumericColumn
field="Margin"
headerText="Margin"
width="*>100"
positiveSuffix="%"
horizontalAlignment="center"
/>
<IgrNumericColumn
field="Profit"
headerText="Profit"
width="*>100"
positivePrefix="$"
showGroupingSeparator="true"
/>
<IgrTextColumn
field="Status"
headerText="Status"
width="*>110"
horizontalAlignment="center"
/>
</IgrDataGrid>
</div>
</div>
);
}
}
// rendering above class to the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<DataGridColumnChooserPicker/>);
tsx
コード スニペット
以下は、データ グリッドの列選択 UI の実装方法を示します。
<IgrColumnChooser
ref={this.onColumnChooserRef}
height="100%"
width="250px"
title="Column Chooser"
showAllText="Show All"
hideAllText="Hide All">
</IgrColumnChooser>
<IgrDataGrid
ref={this.onGridRef}
height="100%"
width="100%"
dataSource={this.data}
autoGenerateColumns="false"
columnHidingAnimationMode="SlideOver">
<IgrTextColumn isHidden="true" field="ProductPrice" headerText="Product Price"/>
</IgrDataGrid>
tsx
import { IgrDataGrid } from 'igniteui-react-grids';
import { IgrColumnChooser } from 'igniteui-react-grids';
import { ColumnMovingAnimationMode } from 'igniteui-react-grids';
public grid : IgrDataGrid;
public columnChooser: IgrColumnChooser;
public onGridRef(grid: IgrDataGrid) {
this.grid = grid;
if (this.columnChooser) {
this.columnChooser.targetGrid = this.grid;
this.grid.columnMovingAnimationMode = ColumnMovingAnimationMode.SlideOver;
}
}
public onColumnChooserRef(columnChooser: IgrColumnChooser) {
this.columnChooser = columnChooser;
if (this.grid) {
this.columnChooser.targetGrid = this.grid;
this.columnChooser.showAllText = "Show All";
this.columnChooser.hideAllText = "Hide All";
}
}
ts
API リファレンス
IgrButton
ColumnChooserText
ColumnChooserTitle
IgrColumnChooser
columnHidingAnimationMode
columnShowingAnimationMode
IgrDataGridToolbar