EloquentStudio / StreamTable.js

StreamTable.js streams data for tables in the background, updates and renders them using templating frameworks like Mustache.js, HandleBars.js
http://eloquentstudio.github.io/StreamTable.js/stream.html
MIT License
385 stars 77 forks source link

Use Json instead of Json file #28

Open Snowji-Yama opened 8 years ago

Snowji-Yama commented 8 years ago

Hi,

I would like to use your plugin but I have a problem. In my app, I don't need to use a json file. Is it possible to send a json object directly in option instead of a file ?

I need :

data_url: [ { name: 'Once Upon a Time in the West', rating: '8.7', director: 'Sergio Leone', year: '1968', actor: 'Henry Fonda' }, { name: 'Terminator 2: Judgment Day', rating: '8.6', director: 'James Cameron', year: '1991', actor: 'Arnold Schwarzenegger' }, { name: 'Braveheart', rating: '8.4', director: 'Mel Gibson', year: '1995', actor: 'Mel Gibson' }, { name: 'Oldboy', rating: '8.4', director: 'Chan-wook Park', year: '2003', actor: 'Min-sik Choi' } ]

Instead of : data_url: 'data/movies.json'

Thanks !

jiren commented 8 years ago

Use below code If you don't want to use data url.

 var st = StreamTable('#stream_table', {view: view },  your_json_data);
Snowji-Yama commented 8 years ago

Ok but "your _json_data" will be streamed,100 by 100 for exemple, or full load, ?

jiren commented 8 years ago

No it will not be streamed. It will load all data once and enabled pagaination.

Snowji-Yama commented 8 years ago

So there is not solution to stream with json object ? Not a solution with tempory file ? because in my app I can't create file. I have a php method who return a json and I can send it in my view, that's all.

jiren commented 8 years ago

You need to make a JSON api, which sends JSON data in response of data_url. In example I have used JSON file to run table html page as static without any server.

Snowji-Yama commented 8 years ago

I'm not sure to understand all. I can't change my process, I'm on Symfony and I call in my controller a WebServices who return a JSON. So I can transfer this JSON from my controller to my view. After I don't know to incorporate your streamtable, but I need it because I have lot of data. So if I can create a tempory file json it's goo, else, I don't know :(

jiren commented 8 years ago

Using webservice is a correct solution. Just pass your webservice url to streamtable options.

var st = StreamTable('#stream_table', {view: view,  data_url: "WEBSERVICE URL" }, []);
Snowji-Yama commented 8 years ago

Even if the WS return the complete result ? It's StreamTable will stream step by step the complet result ?

jiren commented 8 years ago

In any case if you load all data at time then there is no use of streaming. You can paginate your WS respose. Streamtable will send you a page records offset.

Snowji-Yama commented 8 years ago

Ok, I will try. Thanks