简体   繁体   English

如何更改 ag-grid (JavaScript) 侧边栏的宽度?

[英]How to change ag-grid (JavaScript) sidebar's width?

I need to change my ag-grid sidebar's width default to 1000px.我需要将 ag-grid 侧边栏的宽度默认更改为 1000px。 Please check the configuration and image.请检查配置和图像。 Thanks谢谢

const listingGridOptions = {
    columnDefs: listingColumnDefs,
    icons: {
        'custom-stats': '<span class="ag-icon ag-icon-custom-stats"></span>'
    },
    sideBar: {
        maxWidth:600,
        toolPanels: [
            {
                id: 'columns',
                labelDefault: 'Columns',
                labelKey: 'columns',
                iconKey: 'columns',
                toolPanel: 'agColumnsToolPanel',
            },
            {
                id: 'filters',
                labelDefault: 'Filters',
                labelKey: 'filters',
                iconKey: 'filter',
                toolPanel: 'agFiltersToolPanel',
            },
            {
                id: 'customStats',
                labelDefault: 'Custom Stats',
                labelKey: 'customStats',
                iconKey: 'custom-stats',
                toolPanel: 'customStatsToolPanel',
            },
        ],
        //defaultToolPanel: 'customStats'
    },
    components: {
        imageRenderer: imageRenderer,
        customStatsToolPanel: CustomStatsToolPanel
    },
    defaultColDef: {
        flex: 1,
        minWidth: 150,
        filter: true,
        resizable: true,
        sortable: true,
        enableRowGroup: true,
        floatingFilter: true
    },
    rowSelection: 'single',
    autoGroupColumnDef: {
        minWidth: 200
    },
    rowGroupPanelShow: 'always',
    onSelectionChanged: onSelectionChanged,
    // use the server-side row model
    rowModelType: 'serverSide',
    serverSideStoreType: 'full',
    animateRows: true,
};

在此处输入图像描述

Override the tool panel width with css and set the width to 1000px like so:用 css 覆盖工具面板宽度,并将宽度设置为1000px ,如下所示:

    .ag-tool-panel-wrapper {
        width: 1000px !important;
    }

Demo .演示

You set each sideBar toolPanel's width .您设置每个 sideBar 工具面板的宽度 You need to set default width per panel, not globally under sideBar.您需要为每个面板设置默认宽度,而不是在侧边栏下全局设置。 This will set the default sidebar width per panel, and still allow for expanding or condensing the bar once opened.这将设置每个面板的默认侧边栏宽度,并且仍然允许在打开后扩展或压缩栏。 If you use the css override the size will be fixed.如果您使用 css override,大小将是固定的。 And only using maxWidth/minWidth per tool panel will force a snap-to effect, without opening the panel in your desired width.并且每个工具面板仅使用 maxWidth/minWidth 将强制产生对齐效果,而无需以所需宽度打开面板。

sideBar: {
    toolPanels: [
        {
            id: 'columns',
            labelDefault: 'Columns',
            labelKey: 'columns',
            iconKey: 'columns',
            toolPanel: 'agColumnsToolPanel',
            width: 1000
        },
        {
            id: 'filters',
            labelDefault: 'Filters',
            labelKey: 'filters',
            iconKey: 'filter',
            toolPanel: 'agFiltersToolPanel',
            width: 250,
            minWidth: 100,
            maxWidth: 300
        },
        {
            id: 'customStats',
            labelDefault: 'Custom Stats',
            labelKey: 'customStats',
            iconKey: 'custom-stats',
            toolPanel: 'customStatsToolPanel',
            width: 400
        },
    ],
    //defaultToolPanel: 'customStats'
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM