Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: how to track click event on rows? #43

Closed
rusjoan opened this issue May 13, 2016 · 12 comments
Closed

Q: how to track click event on rows? #43

rusjoan opened this issue May 13, 2016 · 12 comments

Comments

@rusjoan
Copy link

rusjoan commented May 13, 2016

Really want to smth like:

...
options: {
  onClick: (row) => { },
  ...
}

How to implement click event handler on row for now?
Thanks!

@matfish2
Copy link
Owner

matfish2 commented May 13, 2016

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.

@jonnywilliamson
Copy link

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

A +1 from me too thank you.

matfish2 added a commit that referenced this issue Jun 4, 2016
@matfish2
Copy link
Owner

matfish2 commented Jun 4, 2016

Added onRowClick callback. See the options API.

@jonnywilliamson
Copy link

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

@jonnywilliamson
Copy link

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

@matfish2
Copy link
Owner

matfish2 commented Jun 5, 2016

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'];
    }
})

@jonnywilliamson
Copy link

Ahh.. OK thank you.

@rusjoan
Copy link
Author

rusjoan commented Jun 6, 2016

@matfish2 thanks! :)

@cloud9business
Copy link

cloud9business commented Jul 16, 2016

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.

@matfish2
Copy link
Owner

Can you paste the relevant HTML and JS?

@cloud9business
Copy link

cloud9business commented Jul 16, 2016

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

@matfish2
Copy link
Owner

matfish2 commented Jul 17, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants