score:1
No need to use the click handler of the button. You cannot get row data with that.
Add a colId
to column definition for actions. Then handle the onCellClicked
action of the grid. You can get the row data using params.node.data
.
const [videoName, setVideoName] = useState("");
function onCellClicked(params) {
// maps to colId: "action" in columnDefs,
if (params.column.colId === "action") {
// set videoName for the row
setVideoName(params.node.data.Video_Name);
setOpen(true);
}
}
// grid config
<AgGridReact
...
rowData={response}
onCellClicked={onCellClicked}>
</AgGridReact>
// access videoName in dialog content
<DialogContent>
{/* <iframe width="420" height="315" title="videos" src={id} /> */}
<div>{videoName}</div>
</DialogContent>
Output - Click on any row's play button. Result is that rows video url. You can now use this to play the actual video.
score:1
If I correctly understood the question, it is because in DialogContent
you are mapping through all response
, and showing all of them.
Instead why not here:
const actionButton = (params) => {
setOpen(true);
};
instead of storing true
, store id
(it seems video name could work in your case too) of the row clicked.
Then inside DialogContent
render only one iframe
, with video based on that id
.
PS. You can pass !!id
as open
prop to Dialog, which means if there is something in id
, the Dialog will open (assuming there are no ids with falsy values).
Or you can actually store the whole row itself in state, and then you can more easily access it, here is simple example what I mean:
let data = [
{ name: 'david', id: 0 },
{ name: 'nick', id: 1 },
{ name: 'john', id: 2 },
];
export default function App() {
let [clicked, setClicked] = React.useState(null);
return (
<div>
{data.map((x) => {
return (
<div
key={x.id}
onClick={() => {
setClicked(x);
}}
>
Row {x.name}
</div>
);
})}
<div>Clicked row {clicked && clicked.name}</div>
</div>
);
}
Source: stackoverflow.com
Related Query
- How to play one video from array at a time in ReactJS & AG Grid
- How to play one song from array at a time react js
- ReactJS How to change from array of arrays to one single array
- How to remove one item from an array using filter() in ReactJS - function not working properly
- I want to run a timer after getting time from firebase-database, how to decease time by one second using setInterval() in ReactJS
- How to filter array from one date to another in Reactjs
- How to pass array of data from one component to another component in reactjs
- How I can display only one object from API array Reactjs
- How to render bootstrap grid from array with map in reactjs
- How to get byte array from a file in reactJS
- Lodash - how to pick only one item at a time from nested json?
- how to remove duplicate objects from an array in reactjs
- How to pass data from one component to another ReactJS
- How to pass data from one component to another while using API in reactjs
- How can i get array of object from this data for state and count in reactjs
- How to find length of an array of objects from ReactJS setState?
- React.js + video element: set current play time from react props?
- How to create array from state value and setstate after removing duplicates in reactjs
- ReactJS / Javascript How to remove the duplicate array from multi dimentional array?
- ReactJS - How to remove an item from an array in a functional component?
- How can I render out the items in my array one at a time when returning them?
- How can one property of an object from an array be true if that property of other objects is false?
- How do I properly map an array in which it's coming from one of my properties defined in mapStateToProps for a select drop down in my form?
- How to generate an array for each input value from textBox in reactJs
- how can i extract arrays from one array & convert them in object and put them in a new array?
- How to take a link from one array and assign it to another?
- How to remove a component from an array in Reactjs
- Return a word from a words array when the time is the one from the time array. Javascript - React
- How to display markers from array in reactjs using leaflet charts
- How to get values from one array of objects into another array of objects
More Query from same tag
- How to add a dynamic variable to the array?
- Action sheet not displaying (Ionic Framework)
- Collect Data from the same component which is being rendered multiple times into an array to be sent to the server
- How can I get the right data from database with react
- How to render matrix table form array in react
- Cannot get create-react-app to work
- Why am I not getting data from the reducer when I click on a button?
- SetInterval after 15mins
- How to create state and assign the rows of material-ui-table with static data
- testing react google maps useJsApiLoader using react testing library
- On click returns null instead of an object
- react datetimepicker with meteor
- React.js using Parent's function to control Child's state
- React-router: Pass props in Link and map match data
- ag-grid-react does not render properly
- Rendering json as a table in react js
- Tailwindcss default hide left side drawer on mobile but show when toggle button click
- react material ui Textfield (type=number) validate 10 characters are existing
- React.js State is not defined in class component
- React Popper and React CSStransition
- Routing: passing a prop from one page to another
- Setting screen size on if statement inside function
- Nothing was returned from render; trying to redirect to homepage
- react bootstrap tabs component renders all tabs
- update scroll position every 8 seconds with useState and useEffect?
- redux saga api call is getting executed multiple times for single button click
- React keyboard Event not firing when modal opens
- Object not replacing using spread operator
- Uncaught Error: AllPostsComments.render(): A valid ReactComponent must be returned
- TypeScript React SFC children props type error