How can I generate table thead from serverside field
How can I generate table thead from serverside field
fatihfx
Posts: 9Questions: 3Answers: 0
How can I create table head row from server side field name ?
// DB table to use
$table = 'raporlar_gonderilen';
// Table's primary key
$primaryKey = 'rapor_gonderilen_id';
$column_array_auto_index = 0;
$caat = $column_array_auto_index;
$columns = array(
array( 'db' => '`t1`.`rapor_gonderilen_id`', 'dt' => $caat++, 'field' => 'Table Head 1' ),
array( 'db' => '`t1`.`rapor_gonderilen_id`', 'dt' => $caat++, 'field' => 'Table Head 2' ),
array( 'db' => '`t1`.`gonderim_tarihi`', 'dt' => $caat++, 'field' => 'Table Head Example' ),
array( 'db' => '`t1`.`gonderim_yapilan_epostalar`', 'dt' => $caat++, 'field' => 'bla bla' ),
array( 'db' => '`t1`.`gonderim_yapilan_user_id_ler`', 'dt' => $caat++, 'field' => 'test' )
);
Answers
There are lots of threads with this question. See if either of these help:
https://datatables.net/forums/discussion/33886
https://datatables.net/forums/discussion/60722
Kevin
Thank you for your answer but I can't see any info about my question.
Need to table head like in array: Table Head 1 - Table Head 2 - Table Head Example - ...
here is my array
See this FAQ.
With server-side processing, you’d need to make one Ajax call to get the column information and then another to get the first page of data for the table.
Allan
If I Understand, it's not possible what I want. Thank you.
Can I use field names instead of targets index ?
'field' => 'table Head 1'
like as
targets : 'table head 1'
It is perfectly possible to do, but as the FAQ says, you need to make an extra Ajax call to get the data.
The options for the
targets
parameter in the columns are defined incolumnDefs.targets
.Allan
So how is it implemented? I see that you can target each column (for example: 0 would be column 1), but how do you give it a name and then show it in the final table?
@ferencvaros The -option columnDefs.targets` docs provide the available options:
Are you referring to the header titles? If so use
columns.title
.Kevin
Sorry for the confusion. I'm referring to the <th> content in <thead>.
@ferencvaros
Use
columns.title
to have Datatables build the header.Kevin