Skip to content

Getting row index in dataFormat props function ? #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
akashshinde opened this issue Aug 4, 2016 · 9 comments
Closed

Getting row index in dataFormat props function ? #604

akashshinde opened this issue Aug 4, 2016 · 9 comments

Comments

@akashshinde
Copy link

I can see dataFormat props func expsoses cell and complete row object.

 dataFormat(cell,row) {}

Is there any way to get row index here ?

@akashshinde akashshinde changed the title getting row index in dataFormat props function ? Getting row index in dataFormat props function ? Aug 4, 2016
@AllenFang
Copy link
Owner

@akashshinde, if pagination was enabled, the scope of row index is belong on current page?

@akashshinde
Copy link
Author

@AllenFang yes, pagination is enabled as I am having less than 10 items rendered in table, So it's in current page.

@AllenFang
Copy link
Owner

@akashshinde, I can support this feature in next version.

AllenFang added a commit that referenced this issue Aug 6, 2016
@AllenFang
Copy link
Owner

AllenFang commented Aug 6, 2016

Released on v2.4.0, check this example. Thanks :)

Be carefully, the row index is passed on fourth arguments

@akashshinde
Copy link
Author

@AllenFang Thanks :)
Will check it out

@raymondsiu
Copy link

This is gold. Thanks @AllenFang

@Grinzzekatze
Copy link

Grinzzekatze commented Sep 7, 2017

Hi!
I tried the example but can´t get the row index. When I click my button the function “addRowSorted” only get´s something like this :

Index = Proxy {dispatchConfig : {…} , .. etc.}

What´s wrong with my code? Thanks!

function activeFormatter(cell, row, enumObject, index) {
    debugger;
    console.log(`The row index: ${index}`);
    return (
      <ActiveFormatter index={index } addRowSorted= {this.props.addRowSorted}/>
    );
  }


class ActiveFormatter extends React.Component {

    render() {

        return (
            <IconButton
                iconProps={{ iconName: 'Add' }}
                onClick={(index) => this.props.addRowSorted(index)}
            />
        );
    }
}

addRowSorted(index) {
        debugger;
        let resources = this.props.data.slice();
        var emptyLine = { id: _.random(-100000000000, 0) }
        resources.splice(index + 1, 0, emptyLine);
        // this.setState({ resources }, this.refs.table.added);
    }

@AllenFang
Copy link
Owner

class ActiveFormatter extends React.Component {

    render() {

        return (
            <IconButton
                iconProps={{ iconName: 'Add' }}
                onClick={() => this.props.addRowSorted(this.props.index)}
            />
        );
    }
}

@paradise5455
Copy link

@AllenFang , if the filter of the column is applied, and any filter is made, the row-id will not start with number "1" because the "ID" here is generated based on the product number. For e.g, if we filter the column "name" with value 4, the row id will will show "4". Since the ID is generated incremental, thus cannot deal with it.

Goal: Want to to have row_index for id add incremental, and even after filter the column name, the 1st row index will start/count as no.1.

Question:
If pagination is applied, the row index will always start with number 1, when we turn to page 2, or page 3. if we used own generated row index as below code, how can we fix that ?

For example code below, try to use this:

indexNumber(cell, row, enumObject, rowIndex) { return (<div>{rowIndex + 1}</div>) }

<TableHeaderColumn ref='id' dataField="id" width='70px' dataSort expandable={false} dataFormat={this.indexNumber} > ID </TableHeaderColumn>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants