Put cell data into url string
Put cell data into url string
tuuni
Posts: 8Questions: 1Answers: 0
Link to test case: https://jsfiddle.net/fvky370c/
Error messages shown: address is undefined
Description of problem:
I want to put the cell data into part of iframe url (part of url string). The cell data comes from mysql and the column header is "address" in the database.
The issue is that JS will output error saying that "data.address" is undefined and I am not sure how to fix it.
I may have doing some wrong here, I am not very good at it.
Thanks for help
This discussion has been closed.
Answers
Your test case doesn't run. Without seeing your data and data structure its hard to say what the problem might be. You can use the browser's debugger to see what the variable
data
is.Note that
var data = table.rows().data();
is usingrows().data()
which will return an array of rows. If you want only one row userow()
instead.If you still need help please update the test case to show the issue you are having.
Kevin
Hello,
I can currently post only code part which are not PHP - server-side.
So little bit more information is on this site:
https://stackoverflow.com/questions/66111880/datatables-open-address-with-google-maps-in-bootstrap-modal-window
I somehow need to iterate all rows with the jquery function, I am not sure how to put it. There could be logical error which is the main problem
Use
rows().every()
to iterate all the rows.Kevin
So,
something like this?..
I am not sure if i need to make serverside connection again if i use api. The serverside connection is made at the top of the whole code part.
I'm not sure what you are trying to do when you say you want to loop all the rows and use that data for the iframe URL.
Are you trying to make a request to
https://www.google.com/maps/
for each row?Or are you trying to build a data set of all the rows to send to
https://www.google.com/maps/
once?Maybe you can describe what your table contains and what you are trying to do with it.
Kevin
Alright, ill try to describe.
For the example I made mysql table column "address" which contains addresses: https://prnt.sc/yzz18i
Yes, I would want to do it. So, if you check the mysql example, every row has different address which I want to act as a link which opens in modal and shows corresponding map where the address part comes from mysql table, like so:
Note the d.address
That code snippet looks like it might work. Have you tried it? What happens?
You can use the browser's debugger or console.log statements inside the loop to verify what
d
andd.address
is. If these are correct then you might need to debug something outside of Datatables.Kevin
Ok, so ran the code with console output.
The code actually outputs all the addresses in console, but in the return function there is nothing:
Can the issue be related to js scope chain?
So, I tried this also, but I don't receive any console output if I put it like this:
Sorry, I'm not sure how to implement the logic to build the modal you want with multiple calls to google maps. That is outside the scope of datatables functionality. Maybe Stack Overflow or some other resource will be able to help you build what you need.
Kevin
That's so sad we couldn't find a solution.
Maybe there is another different approach to this, so I post the link for followup:
https://stackoverflow.com/questions/66144478/datatables-javascript-scope-in-return-function-not-working