Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide sorting buttons when printing #236

Open
fulldecent opened this issue Apr 5, 2023 · 5 comments
Open

Hide sorting buttons when printing #236

fulldecent opened this issue Apr 5, 2023 · 5 comments

Comments

@fulldecent
Copy link

You can't sort tables after printing. So the "sort column" buttons in thead should be hidden.

Here is code I am using that fixes the problem:

      /* data tables fix hide sorting buttons when printing */
      @media print {
        table.dataTable>thead .sorting:before {
          display: none;
        }
        table.dataTable>thead .sorting:after {
          display: none;
        }
      }
@AllanJard
Copy link
Contributor

Good call - thanks for the suggestion! Are you using the Print button, or is this just a print of the whole web-page?

@fulldecent
Copy link
Author

You're welcome! I am using the print action from the browser.


Side note: I wanted to add a print button and a download CSV file button to my page. But I need to style and position it myself. I wanted to use:

document.addEventListener('DOMContentLoaded', function () {
    let table = new DataTable('#example');
});
<button onclick="table.something()">CSV</button>

but couldn't figure it out.

@AllanJard
Copy link
Contributor

The button().trigger() method can be used to activate a button's action.

@AllanJard
Copy link
Contributor

You could also initialise our buttons using this method and then insert into the document using the method shown there and style via CSS as needed.

@fulldecent
Copy link
Author

Awesome, thank you! I got my CSV button working. Later will try upgrading to the latest DataTables version and getting a print button to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants