Adding button to each row in react (flux) fixed data table

Harsha Vardhan Putrevu

I'm trying to add button to each row in fixed data table, but I don't know how. My current code:

var Details = React.createClass({    

    getInitialState() {
            return {
              rows: usersStore.getUsersList(),
              filteredRows: null,
              filterBy: null,
            };
          },    

           componentWillMount() {
            this._filterRowsBy(this.state.filterBy);
          },

          _rowGetter(rowIndex) {
            return this.state.filteredRows[rowIndex];
          },

          _filterRowsBy(filterBy) {
            var rows = this.state.rows.slice();        
            var filteredRows = filterBy ? rows.filter(function(row){
              return row.name.toLowerCase().indexOf(filterBy.toLowerCase()) >= 0
            }) : rows;

            this.setState({
              filteredRows,
              filterBy,
            });
          },

          _onFilterChange(e) {
            this._filterRowsBy(e.target.value);
          },

    render: function () {   

        return (

            <div>
                <label>filter by <input onChange={this._onFilterChange} /></label>
                <Table
                 height={200}      
                  rowHeight={30}
                  rowGetter={this._rowGetter}
                  rowsCount={this.state.filteredRows.length}
                  width={450}
                  maxHeight={450}
                  headerHeight={40}>
                  <Column
                    label="Name"
                    width={270}
                    dataKey="name"
                  />
                  <Column
                    label="Age"
                    width={100}
                    dataKey="age"
                  />
                  <Column
                    label="Qualification"
                    width={120}
                    dataKey="Qualification"
                  />
                  <Column label="Edit"
                    width={120}>
                    <button type="button" className="btn btn-default" onClick={this.update}>Update</button>
                  </Column>
                </Table>
            </div>
        );
    }    
})

While using this code it showing datakey is mandatory and if I remove column tags and adding only button in table also its not accepting.

Ramu

Here is the sample code of adding buttons to each row in react fixed data table

    var Table = FixedDataTable.Table;
var Column = FixedDataTable.Column;

var EmpTable = React.createClass({

  getInitialState: function() {
    return {
      rows: [
        {title: "Ramu", rank: "1", year: "2000"},
        {title: "Harsha", rank: "2", year: "1999"},
        {title: "Hussain", rank: "3", year: "1998"},
        {title: "Vamsi", rank: "4", year: "1997"},
        {title: "Mahesh", rank: "5", year: "1996"},
        {title: "Nitesh", rank: "6", year: "1995"},
        {title: "Subbu", rank: "7", year: "1994"},
        {title: "Kamal", rank: "8", year: "1993"},
        {title: "Kishore", rank: "9", year: "1992"},
        {title: "Venu", rank: "10", year: "1991"},
        {title: "Bhasi", rank: "11", year: "1990"},
        {title: "Suresh", rank: "12", year: "1989"},
        {title: "Ramesh", rank: "13", year: "1988"},
        {title: "Narendra", rank: "14", year: "1987"},
        {title: "Anil", rank: "15", year: "1986"}
      ]
    };
  },


  _displayDataForRow(rowData, rowIndex){      

    alert(rowIndex);
    alert(JSON.stringify(rowData));

  },

  _renderButton(cellData, cellDataKey, rowData, rowIndex){

    return <button style={{width: '80%'}} onClick={this._displayDataForRow.bind(null, rowData, rowIndex)}>click</button>;

  },

  _rowGetter(rowIndex) {
    return this.state.rows[rowIndex];
  },

  render: function() {
    return (
      <div>
        <Table
          rowHeight={30}                  
          rowGetter={this._rowGetter}             
          rowsCount={this.state.rows.length}          
          width={500}
          maxHeight={200}
          headerHeight={30}>

          <Column
           label="Name"
           width={200}
           dataKey="title"
          />
          <Column
           label="Rank"
           width={100}
           dataKey="rank"
          />
          <Column
           label="Year"
           width={100}
           dataKey="year"
          />
          <Column
           label="Click"
           width={80}                      
           cellRenderer= {this._renderButton}                 
          />
        </Table>
      </div>
    );
  }
});

EmpTable = React.createFactory(EmpTable);

React.render(EmpTable(), document.body);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Adding button to each row in react (flux) fixed data table

From Dev

Extract table row data with button on that row with jQuery each()

From Dev

Display JSON data in table format with a submit button corresponding to each row

From Dev

get the row data by a button in a react-bootstrap-table

From Dev

Adding delay on loading each row in HTML table

From Dev

Adding ' at the start of each row of a table through sql

From Dev

adding each row value from different table

From Dev

Use by = each row for data table

From Dev

Tooltip for each row in data table

From Dev

Adding new row of data to a jTable with a Button Click

From Dev

Show/Hide button for each row in table

From Dev

React 'this' undefined when adding table row

From Dev

Adding row for missing value in data.table

From Dev

Normalize each row of data.table

From Dev

Setting data attribute on each row of a jqgrid table

From Dev

Efficient way to divide each row of data table

From Dev

How to add a checkbox dynamically to each row before adding it to a table

From Dev

Adding a bottom line to each row in a table in a PPTX generated by Python

From Dev

Adding text from property after each row in table gsp

From Dev

How to add a checkbox dynamically to each row before adding it to a table

From Dev

Remove data row from table with button

From Dev

fixed-data-table-2 hover row background color

From Dev

Adding row to data frame while maintaining the class of each column

From Dev

Easiest way to add a button on each row of a table HTML

From Dev

How can i add a button on each row in a table in CODENAME ONE?

From Dev

How to put each element of array into table row - table data?

From Dev

In a table each row has an edit button. Show or hide the button depends on another value in this row

From Dev

Adding a Row to an Excel Table

From Dev

Adding row to table with datepicker

Related Related

  1. 1

    Adding button to each row in react (flux) fixed data table

  2. 2

    Extract table row data with button on that row with jQuery each()

  3. 3

    Display JSON data in table format with a submit button corresponding to each row

  4. 4

    get the row data by a button in a react-bootstrap-table

  5. 5

    Adding delay on loading each row in HTML table

  6. 6

    Adding ' at the start of each row of a table through sql

  7. 7

    adding each row value from different table

  8. 8

    Use by = each row for data table

  9. 9

    Tooltip for each row in data table

  10. 10

    Adding new row of data to a jTable with a Button Click

  11. 11

    Show/Hide button for each row in table

  12. 12

    React 'this' undefined when adding table row

  13. 13

    Adding row for missing value in data.table

  14. 14

    Normalize each row of data.table

  15. 15

    Setting data attribute on each row of a jqgrid table

  16. 16

    Efficient way to divide each row of data table

  17. 17

    How to add a checkbox dynamically to each row before adding it to a table

  18. 18

    Adding a bottom line to each row in a table in a PPTX generated by Python

  19. 19

    Adding text from property after each row in table gsp

  20. 20

    How to add a checkbox dynamically to each row before adding it to a table

  21. 21

    Remove data row from table with button

  22. 22

    fixed-data-table-2 hover row background color

  23. 23

    Adding row to data frame while maintaining the class of each column

  24. 24

    Easiest way to add a button on each row of a table HTML

  25. 25

    How can i add a button on each row in a table in CODENAME ONE?

  26. 26

    How to put each element of array into table row - table data?

  27. 27

    In a table each row has an edit button. Show or hide the button depends on another value in this row

  28. 28

    Adding a Row to an Excel Table

  29. 29

    Adding row to table with datepicker

HotTag

Archive