bosskmk / pluto_grid

PlutoGrid is a dataGrid for flutter that can be controlled by the keyboard on desktop and web. Of course, it works well on Android and IOS.
https://pluto.weblaze.dev
MIT License
637 stars 291 forks source link

onSelectedItem function in plutoColumnType.select #935

Open Mohamed-7018 opened 10 months ago

Mohamed-7018 commented 10 months ago

Adding onSelectedItem function that can be passed by the developer (later) .

The function[onItemSelected] is callback function, which is called when selecting an item from the items list. in other words when selecting an item the [onItemSelected] function will be called immediately and it return [PlutoGridOnSelectedEvent] event, so you you can use it make decisions.

for example: let's assume that i want to print a string base on the user's selction, if the user chooses programming I will print "Hello programmer", else I will print "Hello Developer". Bys using the onSelectedItem function we can do this using the following simple code:

   PlutoColumn(
      title: 'Role',
      field: 'role',
      type: PlutoColumnType.select(
        <String>[
          'Programmer',
          'Designer',
          'Owner',
        ],
        onItemSelected: (PlutoGridOnSelectedEvent event) {
          if (event.cell!.value == "Programmer") {
            print("Hello Programmer");
          } else {
            print("Hello Developer");
          }
        },
      ),
    ),

Actually we can use this function in many ways, for example to change other cells data based on the user selection and so many other scenarios.

doonfrs commented 7 months ago

Merged here: https://pub.dev/packages/pluto_grid_plus