Code Monkey home page Code Monkey logo

Comments (5)

abineshPalanisamy avatar abineshPalanisamy commented on August 16, 2024 1

Hi @divan ,

Based on the provided details, the rowColumnIndex obtained from DataGridSource.buildGroupCaptionCellWidget represents solely the row and column index of the caption summary row. Whenever the caption summary row is expanded or collapsed, the rowColumnIndex changes according to the visible rows. This rowColumnIndex is derived from the internal grouped collection.

When using this rowColumnIndex to access the actual data object within grouped rows, we kindly request additional clarification on the expected behavior, along with clear examples and the necessary scenarios from your end. This will significantly aid us in further investigating and promptly providing an appropriate solution.

Regards,
Abinesh P

from flutter-widgets.

divan avatar divan commented on August 16, 2024

@abineshPalanisamy thank you for prompt reply! Here is a quick example. I put some explanation in the buildGroupCaptionCellWidget function comments. My real app case is a bit different (I need to display custom widget for custom type of the common group field), but this example is showing the point.

Currently this code throws an exception, because rowIndex indeed points to 4th internal grouped row, and data has only 3 items. What I'm looking for is to the way to get to single/any/all objects from actual data for the given group.

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'DataGrid Group Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class Employee {
  Employee(this.id, this.name, this.designation, this.salary);
  final int id;
  final String name;
  final String designation;
  final int salary;
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late EmployeeDataSource _employeeDataSource;

  List<Employee> _employees = <Employee>[];

  @override
  void initState() {
    super.initState();
    _employees = getEmployeeData();
    _employeeDataSource = EmployeeDataSource(employees: _employees);
    _employeeDataSource
        .addColumnGroup(ColumnGroup(name: 'designation', sortGroupRows: true));
  }

  List<Employee> getEmployeeData() {
    return [
      Employee(10003, 'Lara', 'Designer', 15000),
      Employee(10004, 'Michael', 'Designer', 15000),
      Employee(10001, 'James', 'Project Lead', 20000),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SfDataGrid(
        source: _employeeDataSource,
        columnWidthMode: ColumnWidthMode.fill,
        columns: [
          GridColumn(
              columnName: 'id',
              label: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  alignment: Alignment.centerRight,
                  child: const Text(
                    'ID',
                    overflow: TextOverflow.ellipsis,
                  ))),
          GridColumn(
              columnName: 'name',
              label: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  alignment: Alignment.centerLeft,
                  child: const Text(
                    'Name',
                    overflow: TextOverflow.ellipsis,
                  ))),
          GridColumn(
              columnName: 'designation',
              label: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  alignment: Alignment.centerLeft,
                  child: const Text(
                    'Designation',
                    overflow: TextOverflow.ellipsis,
                  ))),
          GridColumn(
              columnName: 'salary',
              label: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  alignment: Alignment.centerRight,
                  child: const Text(
                    'Salary',
                    overflow: TextOverflow.ellipsis,
                  ))),
        ],
      ),
    );
  }
}

class EmployeeDataSource extends DataGridSource {
  List<Employee> employees = [];
  EmployeeDataSource({required this.employees}) {
    dataGridRows = employees
        .map<DataGridRow>((dataGridRow) => DataGridRow(cells: [
              DataGridCell<int>(columnName: 'id', value: dataGridRow.id),
              DataGridCell<String>(columnName: 'name', value: dataGridRow.name),
              DataGridCell<String>(
                  columnName: 'designation', value: dataGridRow.designation),
              DataGridCell<int>(
                  columnName: 'salary', value: dataGridRow.salary),
            ]))
        .toList();
  }

  List<DataGridRow> dataGridRows = [];

  @override
  List<DataGridRow> get rows => dataGridRows;

  @override
  DataGridRowAdapter? buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((dataGridCell) {
      return Container(
          alignment: (dataGridCell.columnName == 'id' ||
                  dataGridCell.columnName == 'salary')
              ? Alignment.centerRight
              : Alignment.centerLeft,
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: Text(
            dataGridCell.value.toString(),
            overflow: TextOverflow.ellipsis,
          ));
    }).toList());
  }

  @override
  Widget? buildGroupCaptionCellWidget(
      RowColumnIndex rowColumnIndex, String summaryValue) {
    // get the Employee object of the first person for this group
    // to find a salary
    final idx = rowColumnIndex.rowIndex;
    print('> rowIndex is $idx');
    Employee employee = employees[idx];
    String text = 'Salary of the first person is ${employee.salary}';

    return Container(
        padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 15),
        child: Text(
          text,
        ));
  }
}

Output is:

flutter: > rowIndex is 4
Another exception was thrown: RangeError (index): Invalid value: Not in inclusive range 0..2: 4

from flutter-widgets.

divan avatar divan commented on August 16, 2024

I guess one of the solution might be to use {{Key}} as a summary, and then manually search my underlying data by this value. What I don't like about this approach is the need to convert to/from String, as `summaryString' is a string only...

from flutter-widgets.

abineshPalanisamy avatar abineshPalanisamy commented on August 16, 2024

Hi @divan ,

As of now, We have already considered your request to support for accessing the grouped rows in the DataGridSource.buildGroupCaptionCellWidget function as a feature. We will implement this feature in any of our upcoming releases. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We appreciate your patience and understanding until then. You can follow up with the below feedback for further details,

Feedback link: 50278

Regards,
Abinesh P

from flutter-widgets.

ashok-kuvaraja avatar ashok-kuvaraja commented on August 16, 2024

Hi @divan,

We're closing this issue as of now. You can follow up through the provided feedback link. If you need any further assistance, kindly reopen this issue. We're always happy to help you!

Regards,
Ashok K

from flutter-widgets.

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.