* How can I export a table to HTML with header and footers
@ 2024-10-17 19:14 Dr. Volker Zell
2024-10-18 3:05 ` Raghavendra Nyshadham
0 siblings, 1 reply; 7+ messages in thread
From: Dr. Volker Zell @ 2024-10-17 19:14 UTC (permalink / raw)
To: emacs-orgmode
... see subject
Result should be like the following to be used with the datatable framwork
<table id="example" class="cell-border hover compact" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Technical Author</td>
<td>San Francisco</td>
</tr>
</tbody>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</thead>
</table>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I export a table to HTML with header and footers
2024-10-17 19:14 How can I export a table to HTML with header and footers Dr. Volker Zell
@ 2024-10-18 3:05 ` Raghavendra Nyshadham
2024-10-18 11:35 ` Raghavendra Nyshadham
0 siblings, 1 reply; 7+ messages in thread
From: Raghavendra Nyshadham @ 2024-10-18 3:05 UTC (permalink / raw)
To: emacs-orgmode
On 2024-10-18 00:44 +05:30, Dr. Volker Zell wrote:
> Result should be like the following to be used with the datatable framwork
>
> <table id="example" class="cell-border hover compact" width="100%">
> <thead>
> <tr>
> <th>Name</th>
> <th>Position</th>
> <th>Office</th>
> </tr>
> </thead>
>
> <tbody>
> <tr>
> <td>Tiger Nixon</td>
> <td>System Architect</td>
> <td>Edinburgh</td>
> </tr>
> <tr>
> <td>Ashton Cox</td>
> <td>Technical Author</td>
> <td>San Francisco</td>
> </tr>
> </tbody>
>
> <thead>
> <tr>
> <th>Name</th>
> <th>Position</th>
> <th>Office</th>
> </tr>
> </thead>
> </table>
AFAIK, exporting tables with specific id attributes is not straightforward,
but you can abuse the class attribute by putting the id in it. For example,
if you export a file with the following text (C-c C-e h h), the output may be
like what you want.
Cheers,
Raghavendra.
#+title: Org Tables to DataTables
#+html_doctype: html5
#+html_head: <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
#+html_head: <script src="https://cdn.datatables.net/2.1.8/js/dataTables.min.js"></script>
#+html_head: <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.min.css" />
#+html_head: <script>$(document).ready(function () {$('table.example').DataTable();});</script>
#+html_head: <script>$(document).ready(function () {$('table.another-example').DataTable({lengthMenu: [3, {label: 'All', value: -1}]});});</script>
This is an example table.
#+attr_html: :class example cell-border hover compact :width 100%
| Name | Position | Office |
|-------------+------------------+---------------|
| Tiger Nixon | System Architect | Edinburgh |
| Ashton Cox | Technical Author | San Francisco |
------------------------------------------------------------
This is another example table.
#+attr_html: :class another-example display
| Author | Title | Shelf |
|-------------------+-------------------------+-------|
| Capote, Truman | In cold blood | D3B |
| Chandler, Raymond | The high window | D3B |
| Dai, Mamang | The legends of Pensam | D3B |
| Desai, Kiran | The inheritance of loss | D3B |
| Farrell, J. G. | The hill station | C1B |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I export a table to HTML with header and footers
2024-10-18 3:05 ` Raghavendra Nyshadham
@ 2024-10-18 11:35 ` Raghavendra Nyshadham
0 siblings, 0 replies; 7+ messages in thread
From: Raghavendra Nyshadham @ 2024-10-18 11:35 UTC (permalink / raw)
To: emacs-orgmode
On 2024-10-18 08:35 +05:30, Raghavendra Nyshadham wrote:
> AFAIK, exporting tables with specific id attributes is not straightforward,
> but you can abuse the class attribute by putting the id in it.
I think I was wrong about that:it looks like you can inject a specific
id into a table element with attr_html; I must've misunderstood
something I'd read. So the following should work too, and does not
abuse the class attribute.
Cheers,
Raghavendra.
#+title: Org Tables to DataTables
#+html_doctype: html5
#+html_head: <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
#+html_head: <script src="https://cdn.datatables.net/2.1.8/js/dataTables.min.js"></script>
#+html_head: <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.min.css" />
#+html_head: <script>$(document).ready(function () {$('table#example').DataTable();});</script>
#+html_head: <script>$(document).ready(function () {$('table#another-example').DataTable({lengthMenu: [3, {label: 'All', value: -1}]});});</script>
This is an example table.
#+attr_html: :id example :class cell-border hover compact :width 100%
| Name | Position | Office |
|-------------+------------------+---------------|
| Tiger Nixon | System Architect | Edinburgh |
| Ashton Cox | Technical Author | San Francisco |
------------------------------------------------------------
This is another example table.
#+attr_html: :id another-example :class display
| Author | Title | Shelf |
|-------------------+-------------------------+-------|
| Capote, Truman | In cold blood | D3B |
| Chandler, Raymond | The high window | D3B |
| Dai, Mamang | The legends of Pensam | D3B |
| Desai, Kiran | The inheritance of loss | D3B |
| Farrell, J. G. | The hill station | C1B |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I export a table to HTML with header and footers
@ 2024-10-18 20:38 Dr. Volker Zell
2024-10-19 2:40 ` Raghavendra Nyshadham
0 siblings, 1 reply; 7+ messages in thread
From: Dr. Volker Zell @ 2024-10-18 20:38 UTC (permalink / raw)
To: raghnysh; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1655 bytes --]
Hi
Thanks ... you made my day ... even if haven't asked for displaying 2
tables (or maybe even more) at the same time with all the Datatables
magic glue in ORG syntax this was exactly what I would have asked next
... Yeeeeah your solution (even with the id attribute) works perfectly.
But back to the main question ... is it somehow possible to generate the
<tfoot> footer elements (I just realized that my example was actually
wrong, I used <thead> for <tfoot>... it should look like the following
#+attr_html: :id example :class cell-border hover compact :width 100%
| Name | Position | Office |
|-------------+------------------+---------------|
| Tiger Nixon | System Architect | Edinburgh |
| Ashton Cox | Technical Author | San Francisco |
|-------------+------------------+---------------|
| Name | Position | Office |
=====>
<table id="example" class="cell-border hover compact" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Technical Author</td>
<td>San Francisco</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</tfoot>
</table>
Thx again ... Volker
[-- Attachment #2: Type: text/html, Size: 2225 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I export a table to HTML with header and footers
2024-10-18 20:38 Dr. Volker Zell
@ 2024-10-19 2:40 ` Raghavendra Nyshadham
2024-10-20 13:05 ` Dr. Volker Zell
0 siblings, 1 reply; 7+ messages in thread
From: Raghavendra Nyshadham @ 2024-10-19 2:40 UTC (permalink / raw)
To: Dr. Volker Zell; +Cc: emacs-orgmode
On 2024-10-19 02:08 +05:30, Dr. Volker Zell wrote:
> But back to the main question ... is it somehow possible to generate
> the <tfoot> footer elements ...
>
> <table id="example" class="cell-border hover compact" width="100%">
>
> <thead>
> <tr>
> <th>Name</th>
> <th>Position</th>
> <th>Office</th>
> </tr>
> </thead>
> <tbody>
> <tr>
> <td>Tiger Nixon</td>
> <td>System Architect</td>
> <td>Edinburgh</td>
> </tr>
> <tr>
> <td>Ashton Cox</td>
> <td>Technical Author</td>
> <td>San Francisco</td>
> </tr>
> </tbody>
> <tfoot>
> <tr>
> <th>Name</th>
> <th>Position</th>
> <th>Office</th>
> </tr>
> </tfoot>
> </table>
The Org mode HTML exporter does not seem to provide any facility for
using table footers. You can use the export-filter mechanism of Org
mode to add the footer, but in this case it is simpler to use the
columns.footer option of DataTables, as in the following sample.
#+title: Org Tables to DataTables
#+html_doctype: html5
#+html_head: <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
#+html_head: <script src="https://cdn.datatables.net/2.1.8/js/dataTables.min.js"></script>
#+html_head: <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.min.css" />
#+html_head:<script>$(document).ready(function () {$('#example').DataTable({columns: [{footer: 'Name'}, {footer: 'Position'}, {footer: 'Office'}]});});</script>
#+html_head: <script>$(document).ready(function () {$('#another-example').DataTable({lengthMenu: [3, {label: 'All', value: -1}]});});</script>
This is an example table.
#+attr_html: :id example :class cell-border hover compact :width 100%
| Name | Position | Office |
|-------------+------------------+---------------|
| Tiger Nixon | System Architect | Edinburgh |
| Ashton Cox | Technical Author | San Francisco |
------------------------------------------------------------
This is another example table.
#+attr_html: :id another-example :class display
| Author | Title | Shelf |
|-------------------+-------------------------+-------|
| Capote, Truman | In cold blood | D3B |
| Chandler, Raymond | The high window | D3B |
| Dai, Mamang | The legends of Pensam | D3B |
| Desai, Kiran | The inheritance of loss | D3B |
| Farrell, J. G. | The hill station | C1B |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I export a table to HTML with header and footers
2024-10-19 2:40 ` Raghavendra Nyshadham
@ 2024-10-20 13:05 ` Dr. Volker Zell
2024-10-21 3:40 ` Raghavendra Nyshadham
0 siblings, 1 reply; 7+ messages in thread
From: Dr. Volker Zell @ 2024-10-20 13:05 UTC (permalink / raw)
To: Raghavendra Nyshadham; +Cc: emacs-orgmode
Hi
The columns.footer option of DataTables works like a charm ... but just
curious how would you do it with the export-filter mechanism of Org
mode... mayb this comes in handy later
Thx for you help
Volker
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I export a table to HTML with header and footers
2024-10-20 13:05 ` Dr. Volker Zell
@ 2024-10-21 3:40 ` Raghavendra Nyshadham
0 siblings, 0 replies; 7+ messages in thread
From: Raghavendra Nyshadham @ 2024-10-21 3:40 UTC (permalink / raw)
To: Dr. Volker Zell; +Cc: emacs-orgmode
On 2024-10-20 18:35 +05:30, Dr. Volker Zell wrote:
> how would you do it with the export-filter mechanism of Org mode...
> mayb this comes in handy later
For example, as follows.
#+title: Org Tables to DataTables
#+html_doctype: html5
#+html_head: <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
#+html_head: <script src="https://cdn.datatables.net/2.1.8/js/dataTables.min.js"></script>
#+html_head: <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.min.css" />
#+html_head: <script>$(document).ready(function () {$('#example').DataTable();});</script>
#+html_head: <script>$(document).ready(function () {$('#another-example').DataTable({lengthMenu: [3, {label: 'All', value: -1}]});});</script>
This is an example table.
#+attr_html: :id example :class cell-border hover compact :width 100%
| Name | Position | Office |
|-------------+------------------+---------------|
| Tiger Nixon | System Architect | Edinburgh |
| Ashton Cox | Technical Author | San Francisco |
------------------------------------------------------------
This is another example table.
#+attr_html: :id another-example :class display
| Author | Title | Shelf |
|-------------------+-------------------------+-------|
| Capote, Truman | In cold blood | D3B |
| Chandler, Raymond | The high window | D3B |
| Dai, Mamang | The legends of Pensam | D3B |
| Desai, Kiran | The inheritance of loss | D3B |
| Farrell, J. G. | The hill station | C1B |
# https://list.orgmode.org/87pprzuc74.fsf@gmx.us/T/#m0d6059de7f7301a19faee0de340d9067276f24cb
#+begin_src emacs-lisp :exports results :results none
;; List of lists of the form `(id footer1 footer2 ...)'.
(setq my-tfoot-specs '(("example" "Name" "Position" "Office")
("another-example" "Author" "Title" "Shelf")))
(defun my-insert-tfoot (tfoot-spec)
"Insert a tfoot as per TFOOT-SPEC in the current buffer."
(goto-char (point-min))
(let* ((id (car tfoot-spec))
(footers (cdr tfoot-spec))
(regex (rx (and (literal (format "id=\"%s\"" id))
(*? anychar)
"</tbody>"))))
(when (re-search-forward regex nil t)
(insert "\n<tfoot><tr><th scope=\"col\" class=\"org-left\">"
(mapconcat #'identity
footers
"</th><th scope=\"col\" class=\"org-left\">")
"</th></tr></tfoot>"))))
(defun my-insert-tfeet (text backend _info)
"Insert tfeet for tables in TEXT in HTML export."
(when (org-export-derived-backend-p backend 'html)
(with-temp-buffer
(insert text)
(mapc #'my-insert-tfoot my-tfoot-specs)
(buffer-string))))
(make-local-variable 'org-export-filter-final-output-functions)
(add-to-list 'org-export-filter-final-output-functions #'my-insert-tfeet)
#+end_src
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-21 3:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17 19:14 How can I export a table to HTML with header and footers Dr. Volker Zell
2024-10-18 3:05 ` Raghavendra Nyshadham
2024-10-18 11:35 ` Raghavendra Nyshadham
-- strict thread matches above, loose matches on Subject: below --
2024-10-18 20:38 Dr. Volker Zell
2024-10-19 2:40 ` Raghavendra Nyshadham
2024-10-20 13:05 ` Dr. Volker Zell
2024-10-21 3:40 ` Raghavendra Nyshadham
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).