Categories

Thursday, April 18, 2024
#919814419350 therichposts@gmail.com
DatatableNuxt

Nuxt js Datatable with Dynamic Data Working Example

Nuxt js Datatable with Dynamic Data Working Example

Hello friends, welcome back to my blog. Today this blog post I will tell you, Nuxt js Datatable with Dynamic Data Working Example.

Live Demo

If you are new then you must check below link:

Nuxt Basic Tutorials

Friends now I proceed onwards and here is the working code snippet for Nuxt js Datatable with Dynamic Data Working Example and please use carefully this to avoid the mistakes:

1. Firstly friends we need fresh nuxt.js setup and for this we need to run below commands but if you already have nuxt setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

npm init nuxt-app ecommerceapp

cd ecommerceapp

npm install --save datatables.net-dt

npm install jquery --save

npm install --save axios

yarn dev

2. Now guys please add below code inside pages/index.vue file:

<template>

      
      <div class="container p-5">
          <div class="row align-items-start">
          <table class="table" id="example">
            <thead>
              <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Email</th>
                <th>Job Title</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="user in users" :key="user.id">
                <td>{{user.id}}</td>
                <td>{{user.name}}</td>
                <td>{{user.email}}</td>
                <td>{{user.job_title}}</td>
              </tr>
              
            </tbody>
          </table>
          </div>
        </div>
   
</template>

<script>

import 'jquery/dist/jquery.min.js';
//Datatable Modules
import "datatables.net-dt/js/dataTables.dataTables"
import "datatables.net-dt/css/jquery.dataTables.min.css"
import $ from 'jquery'; 
import axios from 'axios';
export default {
 
  mounted(){
    //API Call
    axios
    .get("https://therichpost.com/testjsonapi/users/")
    .then((res)=>
    {
      this.users = res.data;
      setTimeout(function(){
      $('#example').DataTable();
      }, 1000);
    })
  },
  data: function() {
        return {
            users:[]
        }
    },
}
</script>

Now we are done friends. If you have any kind of query, suggestion and new requirement then feel free to comment below.

Jassa

Thanks

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.