Giter VIP home page Giter VIP logo

Comments (12)

matfish2 avatar matfish2 commented on July 25, 2024 3

Added onRowClick callback. See the options API.

from vue-tables.

matfish2 avatar matfish2 commented on July 25, 2024 1

Save the instance to a variable and replace this with the variable name:

var vm = new Vue({
options:{
    onRowClick:function(row){
    vm.crew = row.FMemeber['CP'];
    }
})

from vue-tables.

matfish2 avatar matfish2 commented on July 25, 2024

The table template doesn't have a click event bound to the row.
I suppose you can either fork the repo and add it to your version, or use JQuery.
I might add it in the future if it turns out to be a common request.

from vue-tables.

jonnywilliamson avatar jonnywilliamson commented on July 25, 2024

Just spent 10 mins looking for this feature in the docs too before discovering it here.

A +1 from me too thank you.

from vue-tables.

jonnywilliamson avatar jonnywilliamson commented on July 25, 2024

Thank you very much @matfish2 . That was much appreciated.

from vue-tables.

jonnywilliamson avatar jonnywilliamson commented on July 25, 2024

Ok I'm probably just being silly but how can I access the vue instance in the onRowClick callback.

At the moment when I try - thisbecomes a window object, not the vue instance.

image

from vue-tables.

jonnywilliamson avatar jonnywilliamson commented on July 25, 2024

Ahh.. OK thank you.

from vue-tables.

rusjoan avatar rusjoan commented on July 25, 2024

@matfish2 thanks! :)

from vue-tables.

cloud9business avatar cloud9business commented on July 25, 2024

I have
var app = new Vue({

app is undefined within the onRowClick callback. The vue-table is nested within a component and this.$parent and this.$root are also undefined within the callback. Any clues?.

I note that $parnet is also undefined within a column template.

from vue-tables.

matfish2 avatar matfish2 commented on July 25, 2024

Can you paste the relevant HTML and JS?

from vue-tables.

cloud9business avatar cloud9business commented on July 25, 2024

app.js

require('spark-bootstrap');

require('./components/bootstrap');

var app = new Vue({
    mixins: [require('spark')]
});

coponents/bootstrap.js

require('./../spark-components/bootstrap');

require('./../my-app-components/bootstrap');

require('./home');

my-app-components/bootstrap.js

var VueTables = require('vue-tables');
Vue.use(VueTables.server, {
    compileTemplates: true,
    highlightMatches: true,
    filterByColumn: true,
    texts: {
        filter: "Search:",
        limit:'Per Page:'
    },
    datepickerOptions: {
        showDropdowns: true
    }
});
Vue.use(VueTables.client, {
    compileTemplates: true,
    highlightMatches: true,
    filterByColumn: true,
    texts: {
        filter: "Search:",
        limit:'Per Page:'
    },
    datepickerOptions: {
        showDropdowns: true
    }
});

HTML (A Laravel Blade template)

<my-app-contacts
        :user="user"
        :contacts="contacts"
        inline-template>
    <div>
        <div v-if="user">
            <div id="people">
                <v-server-table url="{{ route('api.v1.contacts.index') }}" :columns="columns" :options="options"></v-server-table>
            </div>
        </div>
    </div>
</my-app-contacts>

contacts.js

module.exports = {

    props: ['user'],

    /**
     * Load mixins for the component.
     */
    mixins: [
        require('./../../mixins/crud'),
        require('./../../mixins/form'),
        require('./../../mixins/list'),
        require('./../../mixins/tabs')
    ],

    /**
     * The component's data.
     */
    data() {
        return {
            hash: 'contacts',
            columns: ['first_name','last_name','postal_address','postal_city','preferred_phone'
            ],
            options: {
                headings: {
                    first_name: 'First Name',
                    last_name: 'Last Name',
                    postal_address: 'Address',
                    postal_city: 'City',
                    preferred_phone: 'Phone',
                    actions: 'Actions'
                },
                templates: {
                    action: function (row) { return " <a href='javascript:void(0);' @click='$parent.editContact({row})'><i class='glyphicon glyphicon-edit'></i></a> <a href='javascript:void(0);' @click='$parent.approveContactDelete({row})'><i class='glyphicon glyphicon-erase'></i></a>"; }
                },
                columnsDisplay: {
                    postal_address: 'not_mobile',
                    actions: 'not_mobile'
                },
                onRowClick: function(row) {
                    $parent.view(row)
                }
            }
        };
    },

    events: {

        'vue-tables.loading': function (request) {
            console.log('vue-tables loading'); 
        },

        'vue-tables.loaded': function (response) {
            console.log('vue-tables loaded'); 
        }
    }

};

Note that in onRowClick and the action template this, this.$parent, $parent and app are all undefined. I also tried this.$dispatch but that is also undefined. The table seems to work in all other respects.

I can confirm that the vue-tables.loading and vue-tables.loaded events are being dispatched correctly form set-data.js. In set-data.js this is, correctly, an instance of VServerTable.
image
In my onRowClick function this is just a plain Object with all of the v-server properties like columnsDisplay and compileTemplates.
image

from vue-tables.

matfish2 avatar matfish2 commented on July 25, 2024

When using a compiler like browserify or webpack the different modules are scoped and have no immediate access to other modules. You can either export your app variable and import it into contacts.js, or make contacts.js a function that accepts your app instance.

from vue-tables.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.