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

Extend dgrid or dgrid/editor to instantiate dijits based on data in each row #192

Open
neekfenwick opened this issue Jun 5, 2012 · 1 comment

Comments

@neekfenwick
Copy link

I have a very flexible data scheme in my project that allows each data item coming from the backend to define its own display dijit class, so each one is rendered on the frontend using a dijit prototype instantiated using a field in the item itself. I'm having trouble using this approach with dgrid.

I've tried to use dgrid/editor to instantiate dijits using row data, but there seems a chicken-and-egg problem.

Consider my pseudo data:

items: [
    { dijitClass: 'mydijits/Foo', fooData: 1234 },
    { dijitClass: 'mydijits/Bar', barData: 'funky chicken' }
]

The intention is that the first row be rendered using the mydijits/Foo dijit and the second using mydijits/Bar. I'm currently achieving this sort of thing using getObject:

array.forEach(items, function(item) {
  var proto = dojo.getObject(item.dijitClass);
  var d = new proto(item);
  d.placeAt(somewhereUseful);
})

With dgrid, when defining the column structure we have two options..

1/ use dgrid/editor - this requires knowing the dijit class to use for each cell beforehand, e.g. editor({label: 'foo', field: 'bar'}, TheDijitProto). https://github.com/SitePen/dgrid/wiki/Working-with-Widgets looks promising, so the editor knows how to clean up after itself if a dijit was instantiated, but cannot be told to create dijits in a more creative way.

2/ use renderRow or renderCell.
renderRow on an OnDemandList can instantiate my dijit based on data in each item, and return the domNode. However, then it's never cleaned up when the row is destroyed. I tried using the aspect/before code mentioned in 1/ to hook onto the grid's removeRow function to do my own cleanup, but it was never invoked.

I hesitate to say which approach is 'better'. The use of the word 'editor' in dgrid/editor when wanting to simply render a custom dijit in a column makes it sound like it's not the right solution.

@tsemachh
Copy link

  1. I am checking now dgrid and I strongly support that requirements , moreover from my experience in previous frameworks ,
    There's a need to allow what I call business rules in row level ,
    aka when changing a field in a row , being able to replace widget in other column based on that selection.
  2. As for your issue below I would use 1 but would pass it what's ever needed to instantiate the Widget , would let you know if I find better approach.

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

No branches or pull requests

2 participants