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

add or update data? #254

Open
mspanish opened this issue Jul 5, 2020 · 2 comments
Open

add or update data? #254

mspanish opened this issue Jul 5, 2020 · 2 comments
Labels

Comments

@mspanish
Copy link

mspanish commented Jul 5, 2020

Maybe I'm missing the obvious but is there a method do update data, rather than setting the source?

I'm using Papa Parse to stream CSV files which are 30MB+, so I use the chunked option and need to update or add data on each chunk, which I can adjust the size for.

How with Cheetah Grid could I do this? This data is JSON although I can also get it as simple arrays with the headers separate, which is a lot less data coming out of the parser.

My parsing fn:

Papa.parse('http://localhost:5000/followers.csv', {
        header: true,
        download: true,
        delimiter: ";",
        newline: "\r\n",
        skipEmptyLines: true,
        chunk: function(results) {
		let data = results;
		dataTable.insert(data);
                numberFollowers +=results.data.length;
        },
        complete: function(results) {
            console.log('lenny:'+numberFollowers)
        }
});
@mspanish
Copy link
Author

mspanish commented Jul 5, 2020

I can replace data by doing:

grid.records = data;

but it's replacing all my other data on each chunk. So if I have a way to return the data from the grid, I can then just do a concat - is there a method to return the current data?

update: I don't know if this is very memory efficient, but I set my own variable loadedData above my scripts. Then in the data gathering fn, I do this:

data = loadedData.concat(data)
grid.records = data;
loadedData = data;

Then in my data complete fn, I clear it out,

loadedData = []

@ota-meshi
Copy link
Member

Thank you for your question.

As you say, in order to update the array data you need to make an assignment to grid.records.

If you use a DataSource you can write:

const dataSource = new cheetahGrid.data.CachedDataSource({
  get(index) {
    return loadedData[index];
  },
  length: loadedData.length,
});

const grid = new cheetahGrid.ListGrid({
  // ...
  dataSource,
  // ...
})

loadedData.push(...newData)
dataSource.length = loadedData.length

https://future-architect.github.io/cheetah-grid/documents/api/js/grid_data/#using-cheetahgrid-data-datasource-object

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

No branches or pull requests

2 participants