Print Button, row restriction before print
Print Button, row restriction before print
spiderkzn
Posts: 44Questions: 12Answers: 0
Hi,
Please can you help with guidance.
As I have print button on datatables which when clicked it will go to new screen to direct to print option.
So, can it possible that I would like restrict it up to 1000 rows to allow print otherwise it will have message that row need to be less or equal to 1000 to order to print?
As there is action: function (e, dt, node, config) {
Help with if statement.
}
This question has an accepted answers - jump to answer
Answers
You are already 90% of the way there. Combine what you know (needing an
if
statement in theaction
) with the second example from thebuttons.buttons.action
documentation, and a call toalert()
for the warning:Assuming you wish to base it on the rows selected of course. You might want something else. You will probably also need to add a check to make sure at least one row is selected.
Allan
Thank you for it. It work. But other thing for
DataTable.ext.buttons.csvHtml5.print.call(this, e, dt, node, config, cb);
It mention DataTable is not found. as I'm using
$("#tablename").DataTable({....
How do I change DataTable?
by the way the error is:
TypeError: Cannot read properties of undefined (reading 'call')
Look like I've made it to work.
So the printing. How do I make it to print in new tab and printer option instead of csv/pdf etc?
Sorry - it should have been:
The print view should open in a new tab by default.
Allan
Hi Allan,
So it didn't work. But I've make other way
$.fn.dataTable.ext.buttons.print.call(this, e, dt, config, cb,);
So there is error:
TypeError: $.fn.dataTable.ext.buttons.print.call is not a function
By the way I'm using TypeScript not Javascript.
How do I resolve this
When I try this:
$.fn.dataTable.ext.buttons.print.action.call(this, e, dt, config, cb,);
Error:
TypeError: Cannot read properties of undefined (reading 'columns')
https://live.datatables.net/zafifuna/1/edit
Needs the
action
function that is called. It should also extend fromprint
so that it inherits the properties needed for that action.Allan
Hi allan,
I've working and use this one https://datatables.net/forums/discussion/33209/run-script-before-exporting-begins-buttons-plugin
So I can able to make it work but there is error:
Exception Unhandled
TypeError: r is not a function
When I click continue. it does print fine. as is there is way to prevent this error?
Can you update my test case to show the issue please? Or link to the actual page you are working on so I can debug it.
Allan
The error might relate to the missing fifth parameter in the example you linked to, but you will see it in the example I provided above. The fifth (
cb
) parameter was added in newer versions of Buttons.Allan
action: function (
e,
dt,
button,
config,
) {
if (dt.rows().count() <= 1000) {
$.fn.dataTable.ext.buttons.print.action.call(
this,
e,
dt,
button,
config,
);
} else {
alert("The record contain more than 1000. Please use the dropdown boxes to reduce the number of display records before printing");
}
},
Ok let me try add cb
the cb has solved the problem. thank you allan!
action: function (
e,
dt,
button,
config,
cb
) {
if (dt.rows().count() <= 1000) {
$.fn.dataTable.ext.buttons.print.action.call(
this,
e,
dt,
button,
config,
cb
);
} else {
alert("The record contain more than 1000. Please use the dropdown boxes to reduce the number of display records before printing");
}
},
other help please.
When the else appear with alert.
After ok. the print button showing the loading icon.
How to make loading icon disappear from print button?
Check the browser's console for errors.
Update Allan's test case to chow the issue so we can help debug:
https://live.datatables.net/zafifuna/1/edit
Kevin
I copied your code into this test case:
https://live.datatables.net/zafifuna/2/edit
Its easier for us to help you if you provide running test cases replicating your issues.
You are using
buttons.buttons.extend
to make the button aprint
button. This doesn't work and causes the issue you are seeing because now its both aprint
button and custom button. The Custom button required parameters docs state thatbuttons.buttons.text
andbuttons.buttons.action
are required. I changedextend
totext
in the updated test case and now it works.Kevin
Kevin,
I cannot find a solution but I've found a way to remove spinner icon on print.
...
...
...
else {
alert("The record contain more than 1000. Please use the dropdown boxes to reduce the number of display records before printing");
$("[class^='btn btn-secondary buttons-print']").removeClass("processing");
}
...
Maybe you may need add that for next update?
If you can provide me with a link to a test case showing the issue, as Kevin asked for, and it shows an issue that needs a fix for the next release, I'll make that change.
Allan
Hi allan.
See here https://live.datatables.net/zafifuna/3/edit
If you click print the spinner icon will running.