Custom parts list print
This documentation provides a detailed guide on how to override the printPartList
function to customize the printing behavior of the part list in the configurator. In the first part of this documentation we want to focus on an generic implementation of overriden the Rubens onPrintPartList
callback. In the second part we want to show an example case how to generate an PDF with an java script library - if you want to use your own java script library or just do something else with the print part list button you can skip the second part.
Code Sandbox:
If you need some example or just want to copy paste, please have a look in this Code Sandbox.
Overriding the onPartlistPrint callback
1. Step: Initialize the configurator as usual
If you initialize the configurator for the first time please have a look in Getting started.
If you don't want to override the print button but want to hide it you can set the partlist_print
in the init data to false.
2. Step: Override the onPartlistPrint
callback
onPartlistPrint
callbackAs usual you can override the onPartlistPrint
callback with every function you want, we override it in this case with our own custom printPartList
function which is described in the following steps.
Parameters of the onPartlistPrint
Callback
onPartlistPrint
CallbackpartList
: An array containing the parts in the configuration.price
: The total price of the configuration.label
: A label for the configuration.bounds
: The bounds of the configuration.catalogLabel
: A catalog label for the configuration.
Generate custom PDF
As described above this is just an example how you can generate an PDF with our parts list data. You can generate a PDF in every way you prefer. You can find the full code in the Code Sandbox in the print.js
file.
We use for our example: jspdf
1. Step: Translate "0" and "1" of the script to boolean
We have to translate all the "0" and "1" of the parts list to boolean values, because we use "0" and "1" as boolean values in the script.
2. Step: Generate an array of parts list data
Since we want to show the parts list data in the PDF as a table, we need to generate an array out of the parts list data.
This looks a little bit complicated, but basically is formatting all the labels and data of the parts list to a human readable format. Just do it in the way you want to format your data.
3. Step: Initializes the PDF document and add image
Initializes the PDF document with the main label, catalog label, and image.
We now set up the PDF as it is needed for the jspdf library. You can set the font family, font wheight, font size and so on - if you need more information please have a look in the documentation of the jspdf.
Further we add an image on the top right edge.
4. Step: Adding description of the bounds
Besides the image we want to add the bounds - so how big the item is - to the pdf.
5. Step: Adding the parts list table
Now we want to add the parts list table for which we formatted the parts list data in step 2.
6. Step: Final step
Finally you have to call all the function above to set up the PDF with your parts list.
Conclusion
To implement your custom parts list there are some steps needed, as mentioned above you after overriding the onPartlistPrint
callback you can implement printing the parts list PDF in your own way.
If you want to look up the full example please have a look in this Code Sandbox.
Last updated