ratiw / vue-table

data table simplify! -- vuetable is a Vue.js component that will automatically request (JSON) data from the server and display them nicely in html table with swappable/extensible pagination component.
MIT License
1.83k stars 303 forks source link

Should "vuetable:load-success" callback be executed before rending? #111

Closed noru closed 8 years ago

noru commented 8 years ago

I using this event callback to intercept response to set correct pagination data.

However, during my try I found that didn't work because the table row rendering seems already done before my interception.

vuetable:load-success

Type: dispatch Arguments: {Object} response -- the response returned from the server Usage: This event will be triggered when the data was successfully loaded from the server.

In my understanding, it should be called right after the data was returned (before it flows into vuetable).

What's your opinion on that? Plus, I want to ask if there is a way of interception just as vue-resource provided.

Thanks for the work!

ratiw commented 8 years ago

@noru The event in Vue.js is not asynchronous, so you cannot rely on that. It only signifies that the event has occurred. Why would you want to intercept the data like vue-resource?

noru commented 8 years ago

@ratiw The reason I wanted to do so is that, my api doesn't have sufficient "pagination" format and I can't change that internally. It is like:

{ found: 50 start: 0, hit: [ ...{row data array}... ] }

so I have to calculate a legal 'pagination' object and attach it to the original response.

Of cause, I've already done it through vue-resource, but I don't think it is the best place to be. It would be better if such logic is contained by my table component.

I found vue-table is unique in that it feeds itself from API directly, while other table components often have a "row data" sort of property as data source. Can vue-table support that? If not, I think it is a viable requirement for a user may not always have an API or he wants to control/manipulate the data himself (sorting, filtering, etc.)

ratiw commented 8 years ago

@noru I see. I was thinking about adding the data transformation before, but not yet come across any project for that yet.

It's possible and wouldn't be that hard to implement but I'm afraid I will not have time to work on it right now as I'm quite busy and only able to answer short questions here and there.

If you cannot wait and interesting in implementing it, I can point you to where it should be implemented. And maybe send your PR, once you get it working.

noru commented 8 years ago

@ratiw yeah sure, be glad to. shed me some light and I'll see what I can do.

ratiw commented 8 years ago

@noru This is where the requested data was successfully retrieved and set to tableData.

You should call a user-defined method in the parent instance (perhaps named it transform(response.body)) to do the transformation and returns the return to be set to tableData.

noru commented 8 years ago

redirect: https://github.com/ratiw/vue-table/pull/115

ratiw commented 8 years ago

@noru The feature is now available on v1.5.6

noru commented 8 years ago

Thanks @ratiw, already in use!