I found this jQuery Plugin online. The plugin is exactly what I need and I want to add it to my page but my table is created by obtaining the elements from a db. I tried adding it to the page as the jsFiddle sample but pagination just does not show. The only change I am making to the jsFiddle code is the instead of breaking the pages every tbody element I want it to break it every tr element. Here is the code for the table, any suggestion is welcomed.

var columns = ["username", "user_id", "address", "state", "postal_code", "phone", "email"];  
var level_classes = {
 "NEW": "new_client",
 "RENEWAL": "renewing_client",
 "CURRENT": "current_client"
};
$(document).ready(function() {
 $.getJSON("obtainUsers.php", function(data) {
    var $table = $('<table style="width: 100%;">');
    var $tbody = $('<tbody>');
    $table.append($tbody);
    var $tr = null;

    data.forEach(function(user, index) {
        if (index % 4 === 0) {
            $tr = $('<tr>');
            $tbody.append($tr);
        }
        $td = $('<td class="' + level_classes[user.level] + '">');
        columns.forEach(function(col) {
            $td.append(user[col]);
            $td.append($('<br>'));
        });
        $tr.append($td);
    });
    $('.runninglist').append($table);
 });
});

I have never used a plugin before, so any suggestions will be greatly appreciated.

Thank you

Recommended Answers

All 3 Replies

@diafol, what did you do, you made a change in the HTML but is the Javascript where I am failing.

Member Avatar for diafol

You had a link to a fiddle. I thought it was relevant. Also you said you wanted to show just one <tr> element at a time from your table. That's what I did.

The fiddle you supplied was a little squiffy as it had multiple tbodies not sure if that's semantic, but certainly looks odd.

You'll notice I also changed the js, not simply take out the tbody tags - which should give you a clue as to how to implement it in your example.

If your pagination doesn't show, there could be a number of reasons. You don't show where you include the js files in your opening snippet.

Where is the info that you supply to the plug-in? i.e. the element(s) that you pass to it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.