Ag Grid细节网格(表格行展开)Vue Data Grid: Master / Detail


Vue Data Grid: Master / Detail

Master / Detail 细节网格

Master Detail指的是一个叫做Master Grid的顶层网格,它的行可以展开。当行被展开时,另一个网格会显示与被展开行有关的更多细节。出现的网格被称为细节网格。

启用 Master / Detail

可以使用 masterDetail 网格选项启用细节表格,使用 detailCellRendererParams 配置细节行,如下所示:

<ag-grid-vue
    :masterDetail="masterDetail"
    :isRowMaster="isRowMaster"
    :columnDefs="columnDefs"
    :detailCellRendererParams="detailCellRendererParams"
    /* 其它的 grid options ... */>
</ag-grid-vue>

// 启用 细节网格
this.masterDetail = true;

// 指定该详细行是否展开
this.isRowMaster = dataItem => {
    return dataItem ? dataItem.callRecords.length > 0 : false;
};

// 第一列的配置要使用 cellRenderer: 'agGroupCellRenderer'
this.columnDefs = [
    { field: 'name', cellRenderer: 'agGroupCellRenderer' },
    { field: 'account' }
];

// 详细单元格参数配置
this.detailCellRendererParams = {
    // provide the Grid Options to use on the Detail Grid
    // 提供要在细节网格上使用的网格选项
    detailGridOptions: {
        columnDefs: [
            { field: 'callId' },
            { field: 'direction' },
            { field: 'number'}
        ]
    },
    // get the rows for each Detail Grid
    // 获得每个细节网格的行数
    getDetailRowData: params => {
        params.successCallback(params.data.callRecords);
    }
};

下面的示例显示了一个简单的细节网格,其中配置了上述所有内容。

  1. 设置网格属性 masterDetail=true。这告诉网格允许展开行来显示细节网格。
  2. 将一个主网格列上的 cellRenderer设置为 "agGroupCellRenderer"。这告诉网格,我们使用了分组的渲染器,那这一列就拥有了展开/折叠功能。
  3. 设置详细单元格渲染器参数 detailGridOptions。这包含了对细节网格的配置,比如要显示哪些列,以及你想在细节网格内启用哪些网格功能。
  4. 详细单元格渲染器参数 getDetailRowData提供一个回调。该回调被每个细节网格调用,并设置每个细节网格中要显示的行。

要了解更多关于 detailCellRendererParams的配置,请参见 Detail
Grids
部分。

Master Detail 网格示例

行模型 Row Models

当使用 Master/Detail时,Master Grid必须使用Client-SideServer-Side模型。它不支持使用 ViewportInfinite行模型。

另一方面,详细网格可以使用任何行模型。

API

Master Detail Properties(主细节属性)

Top level Master Detail properties available on the Grid Options:
网格选项中可用的顶层主细节属性:

  • masterDetail: boolean
    • 设置为 true以启用 Master Detail
    • 默认值 false
  • isRowMaster: IsRowMaster
    • 回调,与 Master Detail一起使用,以确定某行是否应该是主行。如果返回 false,该行将不存在详细的记录。
isRowMaster: IsRowMaster<TData>;

interface IsRowMaster<TData = any> {
    (dataItem: TData) : boolean
}
  • detailCellRenderer: any
    • 提供一个自定义的 detailCellRenderer,当主行被展开时使用。参见 Custom Detail
  • detailCellRendererParams: any
    • 指定详细单元格渲染器要使用的参数。也可以是一个提供参数的函数,以实现参数的动态定义。参见 Detail Grids
  • detailRowHeight: number
    • 为每个细节行设置固定高度(像素)。参见Fixed Height
  • detailRowAutoHeight: boolean
    • 设置为 true可以使细节网格动态地改变它的高度以适应它的行。参见 Auto Height
  • embedFullWidthRows: boolean
  • keepDetailRows: boolean
    • 设置为 true是为了在再次显示时保留细节行。
    • 默认值 false
  • keepDetailRowsCount: number
    • 设置要保留的细节行数。
    • 默认值 10

Detail Cell Renderer Params(详细单元格渲染器参数)

详细单元格渲染器的参数在 detailCellRendererParams对象上可用的有:

IDetailCellRendererParams<TData = any, TDetail = any>接口上的可用属性:

  • detailGridOptions: GridOptions<TDetail>
    • 提供用于细节网格的网格选项。
  • getDetailRowData: GetDetailRowData<TData, TDetail>
    • 一个提供在细节网格中显示哪些行的函数。
getDetailRowData: GetDetailRowData<TData, TDetail>;

interface GetDetailRowData<TData = any, TDetail = any> {
    (params: GetDetailRowDataParams<TData, TDetail>) : void
}

interface GetDetailRowDataParams<TData = any, TDetail = any> {
  // Row node for the details request. 
  node: RowNode<TData>;
  // Data for the current row. 
  data: TData;
  // Success callback: pass the rows back for the grid request. 
  successCallback(rowData: TDetail[]): void;
}
  • refreshStrategy: 'rows' | 'everything' | 'nothing'
    • 定义如何在主网格的数据变化时刷新详细网格。
  • template: string | TemplateFunc
    • 允许改变细节网格周围使用的模板。
template: string | TemplateFunc<TData>;

interface TemplateFunc<TData = any> {
    (params: ICellRendererParams<TData>) : string
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用:npm ERR! 404 Not Found - GET https://registry.npmmirror.com/@vue/vue-loader-v15 - [NOT_FOUND] @vue/vue-loader-v15 not found vue 安装npm i element-ui -S 等 组件 报错 npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmmirror.com/@vue/vue-loader-v15 - [NOT_FOUND] @vue/vue-loader-v15 not found npm ERR! 404 npm ERR! 404 '@vue/vue[email protected]' is not in the npm registry. npm ERR! 404 You should bug the author to publish it (or use the name yourself!) npm ERR! 404 It was specified as a dependency of '@vue/cli-service' npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url. 根据引用的内容,这个错误是由于找不到vue-awesome-swiper的tarball数据所导致的。vue-awesome-swiper的tarball数据位于http://172.168.251.67:4873/vue-awesome-swiper/-/vue-awesome-swiper-3.1.3.tgz。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [npm install -g cnpm --registry=https://registry.npm.taobao.org报错](https://blog.csdn.net/qq_36853469/article/details/99900961)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [ist的matlab代码-gitlab-uberspace-tutorial:如何在https://uberspace.de上安装GitLab](https://download.csdn.net/download/weixin_38543120/19078868)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [ 404 Not Found - GET https://registry.npmmirror.com/@vue%2fvue-loader-v15 - [NOT_FOUND] @vue](https://blog.csdn.net/qq_51307593/article/details/127484795)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值