GithubHelp home page GithubHelp logo

Comments (1)

bosskmk avatar bosskmk commented on May 22, 2024 1

https://weblaze.dev/pluto_grid/build/web/index.html#feature/value-formatter

Updated to version 0.1.18.
You can check it out at the demo link.


Ignore the comments below.

It seems to be a necessary feature, but it doesn't exist right now.
I'll add it soon (perhaps in a week...).
Thanks for the good question.

Until then, you can handle it like below.
handle each time the value changes in onChanged or
You can handle it when you tap the save button from onLoaded to the stateManager. Or you can handle it by adding an event to the changeNotifier with stateManager.addListener.

If you have more questions, please ask.

I will close this issue when I add a feature.

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

import '../../widget/pluto_example_button.dart';
import '../../widget/pluto_example_screen.dart';

class NumberTypeColumnScreen extends StatefulWidget {
  static const routeName = 'feature/number-type-column';

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

class _NumberTypeColumnScreenState extends State<NumberTypeColumnScreen> {
  List<PlutoColumn> columns;

  List<PlutoRow> rows;

  PlutoStateManager stateManager;

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

    columns = [
      PlutoColumn(
        title: 'Id',
        field: 'id',
        type: PlutoColumnType.text(),
      ),
      PlutoColumn(
        title: 'Permission',
        field: 'permission',
        type: PlutoColumnType.select(['Block', 'Use']),
      ),
    ];

    final rowsFromServer = [
      {
        'id': 'user1',
        'permission': 0,
      },
      {
        'id': 'user2',
        'permission': 1,
      }
    ];

    rows = rowsFromServer.map((e) {
      return PlutoRow(cells: {
        'id': PlutoCell(value: e['id']),
        'permission': PlutoCell(
          value: e['permission'] == 0 ? 'Block' : 'Use',
        ),
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return PlutoExampleScreen(
      title: 'Number type column',
      topTitle: 'Number type column',
      topContents: [
        Text('A column to enter a number value.'),
      ],
      topButtons: [
        PlutoExampleButton(
          url:
              'https://github.com/bosskmk/pluto_grid/blob/master/example/lib/screen/feature/number_type_column_screen.dart',
        ),
      ],
      body: Column(
        children: [
          PlutoGrid(
            columns: columns,
            rows: rows,
            onChanged: (PlutoOnChangedEvent event) {
              if (event.column.field == 'permission') {
                final changedPermission =
                    event.row.cells['permission'].value == 'Block' ? 0 : 1;

                // update
                // permission = changedPermission
                // id = event.row.cells['id'].value
              }
            },
            onLoaded: (PlutoOnLoadedEvent event) {
              stateManager = event.stateManager;
            },
          ),
          FlatButton(
            onPressed: () {
              final List<Map<String, dynamic>> rowsToUpdate =
                  stateManager.rows.map((e) {
                return {
                  'id': e.cells['id'].value,
                  'permission': e.cells['permission'].value == 'Block' ? 0 : 1,
                };
              });
              // update rowsToUpdate
            },
            child: Text('Save'),
          ),
        ],
      ),
    );
  }
}

from pluto_grid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.