vitmalina / w2ui

UI widgets for modern apps. Data table, forms, toolbars, sidebar, tabs, tooltips, popups. All under 120kb (gzipped).
http://w2ui.com
MIT License
2.65k stars 730 forks source link

Different options for the grid:columns:editable:select #1517

Open pierpaolocira opened 7 years ago

pierpaolocira commented 7 years ago

Hi, I would like to know if it is possible to do (or if it is possible to implement) what I'm asking.

In short imagine: a grid element -> an editable field -> the type of that field is "select".

Currently I see the possibility to define all available options for that select by the "items" property.

{
  ...
  columns: [
    ...
    { field: 'type', 
      editable: {
        type: 'select',
        items: myOptionsArray
      }
    }
  ]
}

But... what if for a given set of rows I would like to modify the set of available option for that field?

This can be helpful for cascade selects, and when the application logic requires specific behaviour.

So, if it isn't already implemented, my idea is to maintain the current "global" items array, but to allow defining a custom array for specific rows.

mpf82 commented 7 years ago

You can probably do this by overriding grid.getCellEditable() - and return different editable objects based on your row.

Unfortunately, AFAIK, there are no examples or docs for this, so you would have to dive into the sources.

I did something similar with getCellValue here, maybe that helps as a starting point.


Edit: it might be even easier, because editable can be a function instead of an object. So unless you're loading your column definitions from a static JSON as I do, you should be fine with a function instead of overriding getCellEditable.

pierpaolocira commented 7 years ago

@mpf82 thanks for your reply... Just a point... I think only the "editable" property of the columns.field property is a function... but it effects all the rows (nothing specific here http://w2ui.com/web/docs/1.5/w2grid.columns , useful info from examples) Instead, the "editable" propery of the the row property seems to just be a boolean value, that needs the column.editable property set ( http://w2ui.com/web/docs/1.5/w2grid.records ) So the latter solution doesn't allow for what I'm searching for. I think I have to go in depth with the former...