Naming columns after table creation for SSP?

Naming columns after table creation for SSP?

ahallahall Posts: 9Questions: 1Answers: 0

Hello all,
I'm getting server-side processing working. It's going pretty well, but one problem is my inability to match columns to fields in my results. I work with associative results, always using
fetch(PDO::FETCH_ASSOC);
for getting results. I have to adjust what I'm asking from the database often enough that it's far easier to work with strings than numbers that change.

I therefore want to match Datatable's columns with my results based on name. That is, rather than:

$newDT["data"][] = $row;
I'd like:
$newDT["data"]["myCol"] = $row["myCol"];

Here's the problem. I can't use the column naming method given in the docs, the one where you define names when the table is first generated in Javascript. My setup is hard to describe, but essentially, I have one function in utils.js that generates Datatables from any table it's asked to. Tables can have seven or eight columns, depending on which page the table comes from, and each page has different column names for the first two or three columns.

Before I start refactoring my Javascript to name columns on a per-page basis, is there any way I can just assign the names after the fact? That is, in the PHP that generates the AJAX response which includes the first table, can I add anything to make the columns have names that SSP can pick up? Maybe a data-* attribute, like data-datatable-column-name? Thank for any suggestions, and sorry this may not be super clear. My question seems clear enough, but the reason I can't name columns initially may not be. I'd give a link, but the web service isn't open to anyone outside of our sales team, and I don't have a demo one set up.

This discussion has been closed.