Javascript Table Creation then add dataTable not working

Javascript Table Creation then add dataTable not working

MatalinaMatalina Posts: 5Questions: 0Answers: 0
edited May 2012 in General
Here is my code:
[code]
$('#' + type[1] + "Info").html('Project NameDeadlineActions');
var projects = Project.get();
for(var projectID in projects) {
if(projects.hasOwnProperty(projectID)) {
if(projects[projectID][2] == 0) {
open = 'Edit Complete ';
}
else {
open = 'Completed! ';
}
$('#' + type[1] + "Info tbody").append('' + projects[projectID][0] + '' + (projects[projectID][1] != null?projects[projectID][1]:'') + '' + open + 'Delete');
}
}
$('#proj_table').dataTable({
bPaginate: true,
sPaginationType: 'full_numbers',
bStateSave: true,
});
[/code]

I am not getting any errors, but DataTable is not being applied to the table. DataTable has not been initialized prior.

Replies

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Looks like it should work to me. What do you get on the console if you add:

    [code]
    console.log( $('#proj_table')[0] );
    [/code]

    Allan
  • MatalinaMatalina Posts: 5Questions: 0Answers: 0
    Well the table is created correctly so it's being added to the dom.

    When I do the code suggested I get the table.
  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    In that case, I'm afraid I don't know what it wrong with the code giving - it looks like it should work. The only thing I see wrong is the trailing comma after bStateSave, but most browsers will cope with that.

    I think I'd probably need to see the page in action to be able to offer any further help.

    Allan
  • MatalinaMatalina Posts: 5Questions: 0Answers: 0
    I will get it on a live server and post a link to it.
  • MatalinaMatalina Posts: 5Questions: 0Answers: 0
    edited May 2012
    http://aliciawilkerson.com/projman/

    Datatables is applied to the project tab with the View Command.

    This uses local storage so you can add your own data.; It is not stored on my server.
  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    The thing that is standing out for me is that i your HTML the table has an id of "taskInfo", while your DataTable initialiser above refers to 'proj_table'.

    Allan
  • MatalinaMatalina Posts: 5Questions: 0Answers: 0
    edited May 2012
    The table isn't taskInfo it's a div outside of the table. The table is named proj_table.

    taskInfo is a div.

    And you are looking at the wrong tab. You need to be under Projects to see the code. Tasks has not been set up.

    [code]




    Project Name
    Deadline
    Actions






    [/code]
This discussion has been closed.