How to use JSbarcode with dataTables

How to use JSbarcode with dataTables

TridindTridind Posts: 9Questions: 3Answers: 0

Hello I am trying to use JSbarcode on a single column in my data table. I am not sure how to initialize JSBarcode per cell?

This is how I am currently populating that column

{ data: "barCode",
"render": function(data, type, row){
return '<svg class="barcode" jsbarcode-value="' + data + '" ></svg>'
}
}

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948

    Looks like you need to initialize the bar code using this:

    JsBarcode(".barcode").init();
    

    Since Datatables only has the current page display in the DOM this initialization will only work for the first page. You can use draw to run the initialization against each page as it is drawn, like this:
    http://live.datatables.net/cawekipa/1/edit

    However I'm not sure if there will be problems, like memory leaks, if the same ells are initialized multiple times. For example the first page is initialized, go to the second and then it is initialized. Go bak to the first and all the cells are re-initialized. Might be ok but I'm not sure. I don't see a method to destroy the barcode.

    You can test this or contact the developer.

    Kevin

  • TridindTridind Posts: 9Questions: 3Answers: 0

    This should be fine. The only problem I have is its not running on initial load but once you click the pagination it will run. How can I make it also run on initial load?

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948
    Answer ✓

    Try initComplete.

    Kevin

  • TridindTridind Posts: 9Questions: 3Answers: 0

    Thank you, with both of them it works!

Sign In or Register to comment.