Use multiple indexes in the same array on server side
Use multiple indexes in the same array on server side
XmLmX2
Posts: 4Questions: 2Answers: 0
Hello guys. So I'm using DataTables and I love it, but I have a problem on server-side processing. I have this code:
$columns = array(
array(
'db' => 'user_id',
'dt' => 0,
'formatter' => function( $d, $row ) {
return "<a href='user.php?id=" . $d . "'> USERNAME </a>";
}
)
);
Instead of USERNAME I want to select from database the column "username". How can I do that?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I'm not sure if there is a better way on the server-side portion to do this with the stock ssp file. Instead of using the formatter you could also select the username column, then do something like this in the datatables JS portion to build the value of the cells to what you are looking for. Then you just need to hide the username column on the front end. I think you can just not even call it in the columns to accomplish that but still use the data from it.
You can also edit the ssp.class.php file if you need it to be more flexible. Here is an example of mine.
Thank you, this works just fine, but what if I have more columns and I want them to display normally?
Should be the same way, you'd just skip over the column you didn't want to display which is
'dt'=>1
in this example. The fnCreatedCell is optional.Perfect! Thank you!