1

I want use jsgrid.min.js to create table in vue component.I should call this in jsgrid.min.jsfunction

jsGrid(..)

how can i do this?(call a function that placed outer the vue component in component )

component.vue

<template>
    <div id="jsGrid">

    </div>
</template>

<script>
    export default {
        data: () => ({
        name: "mja"
    }),


    mounted () {

        $("#jsGrid").jsGrid({
            width: "100%",
            height: "500px"

            });

    }
    }
</script>

<style scoped>

</style>

error

[Vue warn]: Error in mounted hook: "TypeError: $(...).jsGrid is not a function"

I actually embedded src file

<script type="text/javascript" src="{{ asset('plugins/jsgrid/dist/jsgrid.min.js')}}"></script>
1
  • 1
    I think this codepen is what you're looking for. Commented Apr 13, 2018 at 9:40

1 Answer 1

2

You Need To Include Jquery as jsGrid using Jquery , Here is Working Demo :)

var app = new Vue({
  el: '#app',
  mounted:function(){
        jQuery("#jsGrid").jsGrid({
        width: "100%",
        height: "400px",
        inserting: true,
        editing: true,
        sorting: true,
        paging: true,
        data: this.clients,
        fields: [
            { name: "Name", type: "text", width: 150, validate: "required" },
            { name: "Age", type: "number", width: 50 },
            { name: "Address", type: "text", width: 200 },
            { name: "Country", type: "select", items: this.countries, valueField: "Id", textField: "Name" },
            { name: "Married", type: "checkbox", title: "Is Married", sorting: false },
            { type: "control" }
        ]
    });
  },
  data: {
    message: 'Hello Vue App!',
    clients : [
        { "Name": "Otto Clay", "Age": 25, "Country": 1, "Address": "Ap #897-1459 Quam Avenue", "Married": false },
        { "Name": "Connor Johnston", "Age": 45, "Country": 2, "Address": "Ap #370-4647 Dis Av.", "Married": true },
        { "Name": "Lacey Hess", "Age": 29, "Country": 3, "Address": "Ap #365-8835 Integer St.", "Married": false },
        { "Name": "Timothy Henson", "Age": 56, "Country": 1, "Address": "911-5143 Luctus Ave", "Married": true },
        { "Name": "Ramona Benton", "Age": 32, "Country": 3, "Address": "Ap #614-689 Vehicula Street", "Married": false }
    ],
    countries :[
        { Name: "", Id: 0 },
        { Name: "United States", Id: 1 },
        { Name: "Canada", Id: 2 },
        { Name: "United Kingdom", Id: 3 }
    ],
    
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" />
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" />
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>

<div id="app">
 {{ message }}
<div id="jsGrid"></div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

how I convert it to component ?. if I use component i will have Previous error!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.