how do you add custom code in a cell?
how do you add custom code in a cell?
Say I have a table with 4 or 5 fields:
id, title, preview (a link), publish, code
The code fields needs to display some shortcode based on the $id, something like:
{code%get-gallery.php%6%2}
i.e.
$arg1 = is code
$arg2 = name of code to execute
$arg3 = limit (# of images to display)
$arg4 = # bootstrap columns
In a simple situation the arguments are static. In a more complex version the arguments will vary based on the $id and some other fields associated with that table.
q1) how would you set up the static version?
q2) how do you set up the complex version?
This question has accepted answers - jump to:
Answers
Hi @koniahin ,
For both, you can use
columns.render
- that will allow you to define in real-time what that column will display. You could build that string exactly as you like.I'm not sure what you mean by "code to execute", you won't be able to execute code in that table, but it will respond to standard jQuery events as in this example,
Cheers,
Colin
code to execute - misnomer my bad. the goal is to display a shortcode to the administrator which he/she can copy into an article. the shortcode/code is to be dynamically created by some information associated with the listed item. it will most likely require on running a subquery against that item to get some potential arguments.
at this time i'm shooting from the hip; will check into columns.render
Ideally you would want to include that information in the data returned to the client-side on initial request rather than firing off an Ajax request for every cell. For starters DataTables' render method doesn't handle async cases, although you could use
cell().data()
to update a cell's data once the Ajax returns, but secondly you'd quickly DDoS your own server!Allan
columns.render worked; looked at several examples, came up with the following:
I also had to add the id in the list of columns and an ID column in the table display
and also add added an the php processing script.
I'm using % as the field separator. Pretty happy camper.
I'm figuring this stuff out, slowly, methodically. Regarding the ID I found the option to hide the ID in the table display extending columndefs: