gpt4 book ai didi

javascript - 如何使用 JavaScript、React、Angular、Vue 或 ASP.NET MVC 隐藏 Kendo UI 网格列

转载 作者:IT王子 更新时间:2023-10-29 03:07:24 24 4
gpt4 key购买 nike

我正在开发 HTML5 和 JavaScript 网站。

是否可以在 Kendo UI Grid 中隐藏一个列并使用 JQuery 访问该值?

最佳答案

使用 JavaScript

参见 Kendo UI API reference .

在定义网格时隐藏列

你可以添加hidden: true:

$("#gridName").kendoGrid({
columns: [
{ hidden: true, field: "id" },
{ field: "name" }
],
dataSource: [ { id: 1, name: "Jane Doe" }, { id: 2, name: "John Doe" } ]
});

通过 CSS 选择器隐藏列

$("#gridName").find("table th").eq(1).hide();

按列索引隐藏列

var grid = $("#gridName").data("kendoGrid");
grid.hideColumn(1);

按列名隐藏列

var grid = $("#gridName").data("kendoGrid");
grid.hideColumn("Name");

按列对象引用隐藏列

var grid = $("#gridName").data("kendoGrid");
grid.hideColumn(grid.columns[0].columns[1]);

使用 react

参见 Kendo UI for React API reference

在定义网格时隐藏列

你可以设置show: false:

class App extends React.Component {
columns = [
{
title: 'Product Id',
field: 'ProductID',
show: false
},
{
title: 'Product Name',
field: 'ProductName',
show: true
},
{
title: 'Unit Price',
field: 'UnitPrice',
show: true
}
]

constructor() {
super();
this.state = {
columns: this.columns,
show:false
};
}

render() {
return (
<div>
<Grid data={products} >
{this.state.columns.map((column, idx) =>
column.show && (<Column key={idx} field={column.field} title={column.title} />)
)}
</Grid>
</div>
);
}
}

使用 Angular

参见 Kendo UI for Angular API reference

在定义网格时隐藏列

你可以添加[hidden]="true"

@Component({
selector: 'my-app',
template: `
<kendo-grid [data]="gridData" [scrollable]="scrollable" style="height: 200px">
<kendo-grid-column [hidden]="true" field="ID" width="120">
</kendo-grid-column>
<kendo-grid-column field="ProductName" title="Product Name" width="200">
</kendo-grid-column>
<kendo-grid-column field="UnitPrice" title="Unit Price" width="230">
</kendo-grid-column>
</kendo-grid>
`
})

以编程方式隐藏列

@Component({
selector: 'my-app',
template: `
<div class="example-config">
<button (click)="restoreColumns()" class="k-button">Restore hidden columns</button>
</div>

<kendo-grid [data]="gridData" style="height:400px">
<ng-template ngFor [ngForOf]="columns" let-column>
<kendo-grid-column field="{{column}}" [hidden]="hiddenColumns.indexOf(column) > -1" >
<ng-template kendoGridHeaderTemplate let-dataItem>
{{dataItem.field}}
<button (click)="hideColumn(dataItem.field)" class="k-button k-primary" style="float: right;">
Hide
</button>
</ng-template>
</kendo-grid-column>
</ng-template>
</kendo-grid>
`
})

export class AppComponent {
public gridData: any[] = sampleCustomers;

public columns: string[] = [ 'CompanyName', 'ContactName', 'ContactTitle' ];

public hiddenColumns: string[] = [];

public restoreColumns(): void {
this.hiddenColumns = [];
}

public hideColumn(field: string): void {
this.hiddenColumns.push(field);
}
}

使用 Vue

参见 Kendo UI for Vue API reference

在定义网格时隐藏列

你可以添加:hidden="true"

<kendo-grid :height="600"
:data-source-ref="'datasource1'"
:pageable='true'>
<kendo-grid-column field="ProductID" :hidden="true"></kendo-grid-column>
<kendo-grid-column field="ProductName"></kendo-grid-column>
<kendo-grid-column field="UnitPrice" title="Unit Price" :width="120" :format="'{0:c}'"></kendo-grid-column>
<kendo-grid-column field="UnitsInStock" title="Units In Stock" :width="120"></kendo-grid-column>
</kendo-grid>

使用 ASP.NET MVC

参见 Kendo MVC API reference

在定义网格时隐藏列

@(Html.Kendo().Grid<Something>()
.Name("GridName")
.Columns(columns =>
{
columns.Bound(m => m.Id).Hidden()
columns.Bound(m => m.Name)
})
)

使用 PHP

参见 Kendo UI for PHP API reference

在定义网格时隐藏列

<?php
$column = new \Kendo\UI\GridColumn();
$column->hidden(true);
?>

关于javascript - 如何使用 JavaScript、React、Angular、Vue 或 ASP.NET MVC 隐藏 Kendo UI 网格列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26112233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com