Griddle icon indicating copy to clipboard operation
Griddle copied to clipboard

Delete row l callback onClick event

Open prnl-jagadeesh opened this issue 11 years ago • 3 comments

Hi, How i can delete entire row when click on custom component contain in each Grid row ?

prnl-jagadeesh avatar Feb 12 '15 10:02 prnl-jagadeesh

I had this same need and did this:

I added a property to the columnMetadata that contained the customComponent I needed to pass the delete method to, and then inside the custom component used this.props.metadata.deleteCallback.bind(null, this.props.rowData.id)

The deleteCallback is defined in the component scope that has access to the results state. That method then just removes that item from the array, then calls setState on results thus causing a re-render that displays the results without the deleted row.

columnMetadata={[
...
    {
        columnName:'actions', 
        deleteCallback : this.props.deleteCallback, // could also be this.deleteCallback depending where it is defined
        customComponent : ActionsColumn
    }
]} 

...

var ActionsColumn = React.createClass({
    render: function(){
        return (
                <span className="btn btn-danger btn-xs" onClick={this.props.metadata.deleteCallback.bind(null, this.props.rowData.id)}>Delete</span>
        )
    }
});

jzumbrun avatar Mar 24 '15 21:03 jzumbrun

Hi there -- thanks for the example @jzumbrun! We just added a customTableRowComponent (names on some of the custom component things are likely going to change before the 1.0 release to be less confusing) to the source and soon npm.

This may also be something that could be utilized to achieve similar functionality. Please see the brief example here before we get the docs updated. https://github.com/GriddleGriddle/Griddle/pull/134

I'm going to close this for now but please let me know if you have any trouble.

ryanlanciaux avatar Apr 27 '15 04:04 ryanlanciaux

I can't find anything about customTableRowComponent in the current release. I know you said the names could change, but the customRowComponent that's there now seems to only render divs and I can't figure out how to use table rows.

@jzumbrun this worked great, thanks!

regularmike avatar Jun 30 '15 18:06 regularmike