Skip to content Skip to sidebar Skip to footer

What Is The Fastest Way To Create Html Table With Data From Javascript Array?

I have the following code to convert my JSON dataset to html table. I want to know if it is the fastest method, or should I use jqote2 with jquery to write template? Requirements:

Solution 1:

You can use Datatables. It works with jQuery and is also themable. There are quite a few options you can set that can meet your requirements, and even more.

Solution 2:

It is not so easy to do. Take a look at Sencha (extJS), especially Grids - http://www.sencha.com/learn/legacy/Tutorials, http://www.sencha.com/learn/legacy/Tutorials#Grids

Solution 3:

jquery/jqote can do this too:

$('#container tbody').empty().html($('#row_template').jqote(set1));

<scripttype="text/x-jqote-template"id="row_template">
<![CDATA[
    <tr id="<%=this.id%>_valuebox">
        <td><%=this.name%></td>
        <td><%=this.value%></td>
    </tr>
]]>
</script>

Solution 4:

Take a look at the jQuery Templates Plugin.

http://api.jquery.com/category/plugins/templates/

<ulid="movieList"></ul><scriptid="movieTemplate"type="text/x-jquery-tmpl"><li><b>${Name}</b> (${ReleaseYear})</li></script><scripttype="text/javascript">var movies = [
        { Name: "The Red Violin", ReleaseYear: "1998" },
        { Name: "Eyes Wide Shut", ReleaseYear: "1999" },
        { Name: "The Inheritance", ReleaseYear: "1976" }
    ];

    // Render the template with the movies data and insert// the rendered HTML under the "movieList" element
    $( "#movieTemplate" ).tmpl( movies )
        .appendTo( "#movieList" );
</script>

Post a Comment for "What Is The Fastest Way To Create Html Table With Data From Javascript Array?"