How to load JSON Data in jQuery-jTable plugin?

12,630

You can directly load JSON data by setting the 'listAction' to a JSON document .

Example:

actions: {
  listAction: 'url/file.json',
},

Your JSON file needs to have the same fields specified and the next structure:

{
 "Result":"OK",
   "Records":[
    {"PersonId":1,"Name":"Benjamin Button","Age":17,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":2,"Name":"Douglas Adams","Age":42,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":3,"Name":"Isaac Asimov","Age":26,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":4,"Name":"Thomas More","Age":65,"RecordDate":"\/Date(1320259705710)\/"}
   ]
}

The common way is to point the 'listAction' to a server side script (PHP,ASP.NET...) that return the above JSON object.

Check the listAction API reference for more information: ApiReference-listAction

Share:
12,630
Shobhit Sharma
Author by

Shobhit Sharma

I'm a full-stack developer working with web ecosystem and REST APIs mainly Node.js and modern web frameworks with build tools; since 2013. Besides, hacking into open source projects with multiple programming languages and progressive knowledge of handling or maintaining server infrastructure. I build modern, performant and fundamentally rich applications by focusing on simplicity, clean code and effortlessness for end-user disregarding over-engineered or complicated product use cases. I love startups, entrepreneurship, have enthusiastic nature towards learning new technologies and programming languages while following core computer science background I started with.

Updated on June 04, 2022

Comments

  • Shobhit Sharma
    Shobhit Sharma almost 2 years

    I am working on creating a table form using jTable plugin. It mainly focus for ASP or PHP MVC but I'm trying to implement it with javascript/html and mongo backend.

    I went through entire jTable API documentation and I found out there is possibility of populating json schema api into table, quite similiar in flexigrid.

    The code looks like:

     $(document).ready(function () {
              $('#feeds-table').jtable({
                  title: 'Accounts',
                  pageSize: 15,
                  ajaxSettings: {
                      type: 'GET',
                      dataType: 'json'
                  },
                  actions: {
    
                  },
                  fields: {
                      id: {
                          key: true,
                          list: false
                      },
                      username: {
                          title: 'Username',
                          width: '10%'
                      },
                      email: {
                          title: 'Email',
                          width: '10%'
                      },
                      applications: {
                          title: 'Applications',
                          width: '10%'
                      },
                      sites: {
                          title: 'Sites',
                          width: '10%'
                      },
                      verticals: {
                          title: 'Verticals',
                          width: '10%'
                      },
                      roles: {
                          title: 'Roles',
                          width: '10%'
                      },
                      profiles: {
                          title: 'Record date',
                          width: '30%',
                          type: 'date',
                          create: false,
                          edit: false
                      }
                  }
              });
          });
    

    If anyone can help me to find out where should I use URL property or is there any other method in the API reference to GET the data and display in table. Please let me know!