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

[Help] Must all cells be created upfront? #81

Closed
michaelbushe opened this issue Oct 17, 2024 · 3 comments
Closed

[Help] Must all cells be created upfront? #81

michaelbushe opened this issue Oct 17, 2024 · 3 comments
Labels
question Further information is requested stale

Comments

@michaelbushe
Copy link
Collaborator

Now that the baseball season is over, I'm back into PlutoGrid to create a baseball app for next season. I hope to help out and improve PlutoGridPlus.

The core PlutoGrid API seems weak or even faulty at scale. Am I missing something?
I'm looking for something like Java's JTable/JTableModel - can it be done?

AFAIK with PlutoGrid, for all 50 baseball statistics for all 1,000 players that played in baseball last year, I need make a 50,000 cells upfront even though the user can't see any more than maybe a 200 cells at a time on their screen:

List<PlutoRows> _plutoRows = [];
for each player
  List<PlutoCells> cells = [];
  for each stat
       cell.add(PlutoCell(...));
       _plutoRows.add(PlutoRow(cells: cells));

PlutoGrid(
    columns: _plutoColumns,
    rows: _plutoRows, 
),

Good thing I'm not working with DNA! I'd have to make millions of cells instead of 50,000. This API doesn't scale.

Here's how Java's JTable scales:

  TableModel dataModel = new AbstractTableModel() {
          public int getColumnCount() { return stats.length; }
          public int getRowCount() { return players.length;}
          public Object getValueAt(int row, int col) { 
             return statData[row][col]; /* playerId, statId*/ 
          }
      };
 JTable table = new JTable(dataModel);

The JTableModel is only called for values when the cells are visible. You never make cells, the column renderer is a cell "stamp" and it's backed by the table model.

You might say you need all the cells for summaries but with JTable you just have to special case footer rows:

   TableModel dataModel = new AbstractTableModel() {
          public int getColumnCount() { return stats.length; }
          public int getRowCount() { return players.length + 1 /*(extra footer row)*/;}
          public Object getValueAt(int row, int col) { 
            if (row > players.length) {
              //footer row
              return sumColumn([col])
            }
             return statData[row][col]; /* playerId, statId*/ 
          }
      };

Is there a way to get PlutoGrid's API to be scalable like Java's JTable?
If not, how could I make it so?

@michaelbushe michaelbushe added the question Further information is requested label Oct 17, 2024
@AminBhst
Copy link

AminBhst commented Oct 19, 2024

One way you could get around this issue without having to go through with internal API changes, is by pagination. I still don't know whether or not your problem is with cells in particular or just a high number of rows. But you don't have to create all rows upfront. I'd say you could implement a pagination mechanism of your choice, and then dynamically add the rows to pluto grid based on the page you're on.
You can make use of onLoaded method inside the PlutoGrid widget to do so. Use the insertRows(index, row); method provided by the plugo grid stateManager to dynamically add rows. You don't even have to manually trigger the PlutoGrid rebuild when your page changes. Using the state manager to add rows will automatically trigger a rebuild of PlutoGrid if you want it to.

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Dec 11, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

2 participants