Ajax sourced Datatable v-1.7.5 and with jquery v-1.5

Ajax sourced Datatable v-1.7.5 and with jquery v-1.5

anonymous1anonymous1 Posts: 6Questions: 1Answers: 0

I am trying to create an ajax sourced datatable with datatable library v-1.7.5 and jquery library v-1.5. I am bound to use this version of library only.

Now the datatable is rendered with 'No Data Available in table' message. Please help me to solve this.

Please look on the sample code shown below,

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery DataTable</title>

$(document).ready(function(){ var jsonData = [{"userID":"1","userName":"name1","test":"testing"},{"userID":"2","userName":"name2"},{"userID":"3","userName":"name3"}]; var table = $('#example').dataTable({ ajax: jsonData, columns: [ { data: 'userName' }, { data: 'userID' } ] }); $('#example tbody').bind( 'click', 'tr', function () { console.log( table.row( this ).data().test ); } ); });

</head>
<body>

userID userName

</body>
</html>

Replies

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    DataTables 1.7.x is no longer supported. 1.10.12 is the current release. Aside from that you are assigning a data array to the ajax option (which btw doesn't exist in 1.7). You should use data (aaData in the old notation) if you want to just assign data to the table.

    Allan

  • anonymous1anonymous1 Posts: 6Questions: 1Answers: 0

    Thanks for the reply allan.

    As you said, I replaced the Datatable library with 1.10.4 and jquery library with the 1.12.3.
    Now I am getting 'TypeError: g(...).on is not a function' error.
    Please find the attached screen shot of the error for your reference.

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    I would need a link to the page shoiwng the issue please.

    Also, 1.10.12 is the latest version, not 1.10.4.

    Allan

  • anonymous1anonymous1 Posts: 6Questions: 1Answers: 0

    Hi allan,

    ''TypeError: g(...).on is not a function' is because of another js library I used. After removing that library it got worked.
    Now the datatable taking 30 seconds for making all the 20000 records to show in the table even after enabling "deferRender".

    I feel like, it is constructing the table row only after reading all the 20000 records in the json data source.

    Any idea?

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin
    edited August 2016

    I would need a link to the page showing the issue so I can see what is going on and profile it.

    edit

    I feel like, it is constructing the table row only after reading all the 20000 records in the json data source.

    Yes, that is correct. It has to read all of the data so it can decide what to display (i.e. sort the data set). Server-side processing is available if you want to utilize an SQL server.

    Allan

  • anonymous1anonymous1 Posts: 6Questions: 1Answers: 0

    Is there any way to load the data table row instantly i.e. rendering data table row after reading a json data from the data source and then reading next json data in data source?

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    You mean like using cursors in a file to read it line by line (e.g. C's getline())? As far as I am aware that is not something HTTP supports. They ask the HTTP server for the file and it gives it to you. Only when the file has been fully downloaded will it be available for use - you can't request just parts of it (it won't be efficient over a WAN connection).

    Allan

This discussion has been closed.