How to combine two columns to one?
How to combine two columns to one?
loopers
Posts: 17Questions: 7Answers: 0
Currently I set the columns with the data from the JSON using columns
:
// setting the columns from the html builder
->columns($this->getColumns())
// setting the data
protected function getColumns()
{
return [
['title' => 'Id', 'data' => 'id'],
['title' => 'Status', 'data' => 'status'],
['title' => 'Account Number', 'data' => 'account_number'],
['title' => 'Account Name', 'data' => 'account_name'],
];
}
But I need to combine the account_number
and account_name
in a single column called Account Information
. How should I do that? I got lost in the docs, I'm not sure if it's something to do via columnDefs
, or editColumn
or setting the row data somehow?
Answers
See if this example helps.
Kevin
Also, this example, ignore the fact that it's Editor - the first name/last name field joining is the important bit,
Colin
@kthorngren, @colin, I'm a beginner with datatables, so I'd like to know if I understood correctly: a data table must have some sort of query which returns a JSON response. One of the properties of this JSON response is
data
which includes the columns from the db, numbered from 0 to the last columns.so if my query is
SELECT (col1, col2, col3, col4)...
, and I want to combine col2 and col3, I can do:But, how do I set the correct data? Because in the example it says data: 0, but in my case it should be data: 1? Do I just add it as a property in columnDefs?
Can you post a snippet of the data you get back, please, that will help us tailor an example for you,
Colin
@colin there is any way to join 2 buttons in 1 column?
Like Edit and Delete button in 1 column only.
Sure just use
columns.defaultContent
orcolumns.render
to place as many buttons as you want in the column. Something like this example:http://live.datatables.net/xijecupo/1/edit
Kevin
Hi @kthorngren thanks for your quick reply.
Well I did
With
but still doesn't work, ant tips?
Thanks in advance, and for the amazing tool!
In what way doesn't it work?
Looks like you are using the Editor. If so maybe this example will help.
Please provide a link to a test case so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Hi @kthorngren
the
<a class="editor-create">+ Criar Novo registo</a>
works in the php/html filebut when I use the same at .js
defaultContent: '<a class="editor-create" >Criar registo</a>',',
just dont open nothing.
I ll dig more about, maybe its some CSS trash code somewhere here
I'm not sure if you are using it exactly as is there, but there is a syntax error:
should be:
Failing that, as Kevin said, we'd need a test case.
Allan