Best plugin practice for dynamic table creation?

Best plugin practice for dynamic table creation?

Hey guys,

I'm working on a plugin that will dynamically create product tables and append them divs (or whatever selectors call the plugin function). So far, it works as planned but the tables are generated by copying an HTML template that is hardcoded onto the view. My code is long so I'm not going to paste all of it but it is essentially like this (very generally and minus all the table logic functions):

<div class="rowtemplate">

(row HTML)


$.fn.block = function(rows, maxrows) {

      var productRows = $(this);

      function createRows(rows) {
            var rowHTML = $('.rowtemplate').html();
            for(var i = 1; i < rows + 1; i++) {
$('<tr class="productrow"></tr>').appendTo(productRows).append(rowHTML);

      function createTable(rows) {
            (bind table logic functions and other stuff)

(bunch of other stuff)
      createTable(rows, maxRows)

So basically when you say ("#div2").block(5, 10), the plugin takes in 5 as rows and 10 as max rows and pipes those into createTable which calls createRows and binds functions to create the table. The issue is that the createRows function works by using the rowtemplate html above (which I basically just made for testing purposes). This means the plugin is obviously not very portable if you have to bring the template with it every time. So I think there are three ways to implement the HTML:

1. Write the HTML template into the view every time the plugin is used (worst option IMO, for reasons I just stated)

2. Hardcode the HTML template into the plugin so that it just gets appended prior to table construction (only once)

3. Link to an external js file that appends it or link to an external html file that contains it (makes things cleaner but also adds external file dependency which is a pain and makes the plugin only usable with the external file)

I'm strongly leaning toward 2 but I don't know what other developers who have worked on similar projects have done, so I'd like to know if there is another option. Thanks.