Skip to content

Discussion about row selection #153

Description

@bjrmatos

Hi, first of all I want to thank all the work @cosminnicula made to bring this functionality to griddle.

I want to discuss a little more this functionality to ensure that the most important use cases are covered

This is my list of things I think should be covered:

  • Types of row selection that must be supported: Single, Multiple (ctrl + click) and Multiple With checkboxes.
// or "multiple", or "multiple.check", or pass false  to desactivate row selection, 
// maybe these options could be variables -> 
// Griddle.SINGLE_SELECTION, Griddle.MULTIPLE_SELECTION, 
// Griddle.MULTIPLE_CHECK_SELECTION, defaults to "single"
<Griddle  results={data} rowSelection="single"  /> 

i propose something like this:

var data = [{
  id: 1,
  name: 'Boris'
}, {
  id: 2,
  name: 'Junior'
}]

var App = React.createClass({
  getInitialState: function() {
    return {
      selectedRow: null // String, Number, or Object[rowId] = rowData, when multiple selection is enabled
    };
  },

  /* we have correct sync between app state and griddle selectedRow data */
  _onRowSelectionChange: function(selectedRow, rowData) {
    /* this is inspired by react-datagrid */

    // `selectedRow` always have all the current selected row(s)
    // on single mode `selectedRow` will be a String, Number value. `selectedRow` -> 2
    // on multiple mode `selectedRow` will be a Object with all the selectedRows `{ [row_id_here]: { [row data props] } }`. `selectedRow` -> { 2: { id: 2, name: 'Junior' } }
    // `rowData` always have the current selected row data, null when un-selecting a row

    /* 
      Here we can do something with rowData.. 
      like show a detail of the person selected in another view..
    */

    this.setState({
      selectedRow: selectedRow
    });
  },

  render: function() {
    return (
      <Griddle 
        results={data} 
        rowSelection="single" 
        selectedRow={this.state.selectedRow}
        uniqueIdentifier="id" // "id" is the default value, I put this only to make the example more clear
        onRowSelectionChange={this._onRowSelectionChange}
      />
    );
  }
});
  • A property to specify the name of the CSS class / classes to add when a row is selected
`rowSelectionCssClass` defaults to 'selected' when no specified
<Griddle results={data} rowSelection="single" rowSelectionCssClass="row-selected another-class" />
  • ensure order of events: onRowSelectionChange -> onRowClick -> onCellClick (a cellClick event would be useful?)

I like to send a pull request with all these features, but first I want to discuss this with you.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions