pluto_grid icon indicating copy to clipboard operation
pluto_grid copied to clipboard

[Feature] Strict column width

Open urielexis64 opened this issue 2 years ago • 4 comments

I am currently facing an issue with the rendered cells, because even though I set a specific width, the table scales its column width as it pleases. So, I think it would be nice to have a boolean property on column called "strictWidth" or something like that, that it works respecting the given width, regardless of the type of autofit the table has.

Thank you for reading.

urielexis64 avatar Jul 20 '22 14:07 urielexis64

I will consider adding this in the next version. thank you

bosskmk avatar Jul 20 '22 14:07 bosskmk

Hey @bosskmk, Min width is also not respected by column ``autoSizeMode: PlutoAutoSizeMode.scale,``` could that be fixed without the need for this boolean?

ted-marozzi avatar Jul 23 '22 00:07 ted-marozzi

Alternatively autoSizeMode: PlutoAutoSizeMode.scale, could take into account column heading width to set its size, right now it just truncades the title

ted-marozzi avatar Jul 23 '22 00:07 ted-marozzi

@ted-marozzi It should be further developed. It currently refers to the default minWidth , not the setting in PlutoColumn.minWidth.

bosskmk avatar Jul 27 '22 10:07 bosskmk

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 26 '22 11:08 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Sep 09 '22 11:09 github-actions[bot]

until appearing next version you can try this:

  final columns = state!.columns;
  for (var element in columns) {
    state!.resizeColumn(element, 0.1);
    state!.resizeColumn(element, -0.1);
  }
  state!.notifyResizingListeners();
}

yairsts avatar Sep 18 '22 14:09 yairsts

Fixed in PlutoGrid 5.4.8 version.

  • Modified so that each PlutoColumn.minWidth is applied.
  • When PlutoColumn.suppressedAutoSize is set to true, it is modified to be ignored in auto size.

As in the example code below, set the width of the column proportionally If you set autoSizeMode to PlutoAutoSizeMode.scale you can get the flex effect.

Columns with width set to 100, 200 are set to flex size in a ratio of 1:2. Columns for which suppressedAutoSize is true are ignored in auto size setting and fixed to the set width.

import 'package:flutter/material.dart';
import 'package:pluto_grid/pluto_grid.dart';

import '../dummy_data/development.dart';

class EmptyScreen extends StatefulWidget {
  static const routeName = 'empty';

  const EmptyScreen({Key? key}) : super(key: key);

  @override
  _EmptyScreenState createState() => _EmptyScreenState();
}

class _EmptyScreenState extends State<EmptyScreen> {
  late List<PlutoColumn> columns;

  late List<PlutoRow> rows;

  late PlutoGridStateManager stateManager;

  @override
  void initState() {
    super.initState();

    columns = [
      PlutoColumn(
        title: 'column1',
        field: 'column1',
        type: PlutoColumnType.text(),
        width: 100,
      ),
      PlutoColumn(
        title: 'column2',
        field: 'column2',
        type: PlutoColumnType.text(),
        suppressedAutoSize: true,
        width: 150,
      ),
      PlutoColumn(
        title: 'column3',
        field: 'column3',
        type: PlutoColumnType.text(),
        width: 200,
      ),
    ];

    rows = DummyData.rowsByColumns(length: 10, columns: columns);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          padding: const EdgeInsets.all(15),
          child: PlutoGrid(
            columns: columns,
            rows: rows,
            onChanged: (PlutoGridOnChangedEvent event) {
              print(event);
            },
            onLoaded: (PlutoGridOnLoadedEvent event) {
              stateManager = event.stateManager;
            },
            configuration: const PlutoGridConfiguration(
              columnSize: PlutoGridColumnSizeConfig(
                autoSizeMode: PlutoAutoSizeMode.scale,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

bosskmk avatar Dec 10 '22 02:12 bosskmk