I can't create table with datas. maybe someone will help me?

I can't create table with datas. maybe someone will help me?

shahenshahen Posts: 18Questions: 2Answers: 0
edited February 2018 in Free community support

This is my code.

table = $('#entries').DataTable({
        lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
        data: data_table,
        aoColumnDefs: [{ aTargets: -1, bSortable: false, bSearchable: true }],
        "aaSorting": [[0,'desc']],
        columns: data_columns,
        'createdRow': function( row, data ) {
            $(row).attr('rowid', data["rowid"]);
            $(row).attr('subid', data["subid"]);
        }
    });

where

data_table = {browser:"Chrome",confirmed:"<i class="hi-icon hi-icon-small icon-not-confirmed" title="Not confirmed yet">0</i>",
country:"Armenia",
date:"<span>2018-02-13</span><br><span>11:39:24</span>",
field1:"hjkh ityui",
field2:"tryjtyu@dfg.df",
field3:"fghryjrtt yryj rtukr ttyeu r",
os:"Windows 7",
rowid:0,
subid:4904559 };

and this is

data_columns =0:{data: "date", title: "&nbsp;Entry Date", mData: "date", sTitle: "&nbsp;Entry Date"}
1:{data: "field1", title: "Name", mData: "field1", sTitle: "Name"}
2:{data: "field2", title: "Email", mData: "field2", sTitle: "Email"}
3:{data: "field3", title: "Your Comments", mData: "field3", sTitle: "Your Comments"}
4:{data: "browser", title: "User's Browser", mData: "browser", sTitle: "User's Browser"}
5:{data: "os", title: "User's OS", mData: "os", sTitle: "User's OS"}
6:{data: "country", title: "User's Country", mData: "country", sTitle: "User's Country"}
7:{data: "confirmed", title: "Confirmed", className: "columnCenter", mData: "confirmed", sTitle: "Confirmed", …}
8:{data: "subid", title: "Submission ID", mData: "subid", sTitle: "Submission ID"}; 

This question has an accepted answers - jump to answer

Answers

  • shahenshahen Posts: 18Questions: 2Answers: 0

    it gives an error "jquery.dataTables.js:58 Uncaught TypeError: Cannot read property 'style' of undefined"

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi Shahen

    The data that you're trying to display (data_table) doesn't match the structure you've defined (data_columns). Plus, data_table doesn't look like a table of data!

    Take a look at this example, it should get you going in the right direction.

    Cheers,

    Colin

  • shahenshahen Posts: 18Questions: 2Answers: 0

    Hi Colin. I am going to learn that exmaple. But when I delete 1 or 2 of data_columns it works perfect))).

  • shahenshahen Posts: 18Questions: 2Answers: 0

    No this example didn't help me.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hopefully this live example will :)

    There's many problems with that initial code above and the organisation of the data. It's probably best to compare the two side by side and see what changes need to be applied.

    Cheers,

    Colin

  • shahenshahen Posts: 18Questions: 2Answers: 0

    Thank You

  • shahenshahen Posts: 18Questions: 2Answers: 0

    Colin my code works perfect in live example. But on site it again shows error Cannot read property 'style' of undefined"!! I read about it. The problem is that the number of <th> tags need to match the number of columns in the configuration. but it doesn't. Why?

    What I have to do?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Beyond that, we'd really need a link to a page showing the issue so we can debug it.

    Allan

  • shahenshahen Posts: 18Questions: 2Answers: 0

    I have written the url Allan. I really tried everything))))

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I don't see a link to your page demonstrating the issue here. Please post it again.

  • shahenshahen Posts: 18Questions: 2Answers: 0

    I got that messege - Your comment will appear after it is approved

  • shahenshahen Posts: 18Questions: 2Answers: 0

    This

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I don't actually see it in the spam queue which is odd. I got your PM though. It don't see the error happening on that page.

    Allan

  • shahenshahen Posts: 18Questions: 2Answers: 0

    I fixed the error. I don't know what is the problem, but I deleted all code, and started again. It's possible I had done an idiotic mistake, know everything is ok. Thank you. You are the best support team ;)

This discussion has been closed.