overriding/hooking dgrid's defaultRenderCell

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

overriding/hooking dgrid's defaultRenderCell

Michael Schall
I'm attempting to override or add functionality the defaultRenderCell.  My goal is to have a tooltip (html title attribute) added to each cell, showing the (formatted) value in the cell.  Looking at the source of Grid.js, it seems that I should be able to add an aspect.after call somehow to defaultRenderCell.  Something like the following:

  var CustomGrid = declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry]);
  aspect.after(CustomGrid, "defaultRenderCell", function (object, data, td, options) {
        td.title = td.innerHTML;
  });

Debugging the code, CustomGrid.defaultRenderCell == null, so I'm doing something wrong.  

From the comment in Grid.js, 

  // expose appendIfNode and default implementation of renderCell,
  // e.g. for use by column plugins
  Grid.appendIfNode = appendIfNode;
  Grid.defaultRenderCell = defaultRenderCell;

it looks like this is supposed to be exposed.

Can someone give me an example of how defaultRenderCell can be overridden/hooked?

Thanks

Mike

________________________________________________________
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: overriding/hooking dgrid's defaultRenderCell

dylanks
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The more typical pattern would be to add a renderCell method to your
column definition.

If dgrid finds either a renderCell or formatter on your column, it will
ignored the defaultRenderCell method.

In your custom renderCell function, you can call up the inheritance
chain if you want to extend default capabilities, or not. In each case,
you would then return a cell.

Given that you want to apply this to every cell, you might prefer to
define a column plugin and apply it to every column...

e.g.


//
define([
        "put-selector/put"
], function (put) {
        return function (column) {
                column.renderCell = function (object, value, cell) {
                        var cellNode = this.inherited(arguments)
                        var tooltip = put(cellNode, "div.tooltip"),
                        // Do something interesting
                        return cellNode;
                };
                return column;
        };
});

And then in the columns that you want to have a tooltip:

var grid = new Grid({
        columns: {
                foo: "Foo", // no tooltip
                bar: tooltip({ label: "Bar" })
        }
}, "someNodeId");

Where tooltip is your local reference to your column plugin.

Is there a specific reason you want to extend defaultRenderCell?

Regards,
- -Dylan

on 12/4/13 8:41 AM (GMT-07:00) Michael Schall said the following:

> I'm attempting to override or add functionality the defaultRenderCell.
>  My goal is to have a tooltip (html title attribute) added to each cell,
> showing the (formatted) value in the cell.  Looking at the source of
> Grid.js, it seems that I should be able to add an aspect.after call
> somehow to defaultRenderCell.  Something like the following:
>
>   var CustomGrid = declare([OnDemandGrid, Keyboard, Selection,
> ColumnResizer, DijitRegistry]);
>   aspect.after(CustomGrid, "defaultRenderCell", function (object, data,
> td, options) {
>         td.title = td.innerHTML;
>   });
>
> Debugging the code, CustomGrid.defaultRenderCell == null, so I'm doing
> something wrong.  
>
> From the comment in Grid.js,
>
>   // expose appendIfNode and default implementation of renderCell,
>   // e.g. for use by column plugins
>   Grid.appendIfNode = appendIfNode;
>   Grid.defaultRenderCell = defaultRenderCell;
>
> it looks like this is supposed to be exposed.
>
> Can someone give me an example of how defaultRenderCell can be
> overridden/hooked?
>
> Thanks
>
> Mike
>
> ________________________________________________________
> Dojo Toolkit: http://dojotoolkit.org/
> Tutorials: http://dojotoolkit.org/documentation/
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
>
> [hidden email]
> To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlKfW+UACgkQ1E2HcBNypM4dvwCgloJkXIwfzQfXGIsgKSwth7Yf
3HEAnjROe4Ia2+Q+3xxwxSgLKPjPLVGL
=8hmU
-----END PGP SIGNATURE-----
________________________________________________________
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Co-Founder, Dojo Toolkit
CEO, SitePen, Inc.  http://www.sitepen.com/
Reply | Threaded
Open this post in threaded view
|

Re: overriding/hooking dgrid's defaultRenderCell

Michael Schall
Dylan - 

As you have suggested, I have currently specified the renderCell on a couple of my columns using the following code:

    { field: "message", label: "Message",
        renderCell: function(object, value, node, options){
            node.title = value;
            domConstruct.place(document.createTextNode(value), node);
        }},

We have large applications (500+ screens) that will potentially be moved to dgrid.  Our current homegrown grid implementation adds a tooltip for every column by default unless overridden.  My goal is to get dgrid to act the same way.  By default, add the tooltip, if you specify a renderCell, you are on your own to add it back in.  I like to not require my developers have to add this code to every column in our application.  

I found the defaultRenderCell function and thought this was the perfect place to hook in so the developer would get the desired result without any code.

Thanks for the quick response!

 


On Wed, Dec 4, 2013 at 10:44 AM, Dylan Schiemann <[hidden email]> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The more typical pattern would be to add a renderCell method to your
column definition.

If dgrid finds either a renderCell or formatter on your column, it will
ignored the defaultRenderCell method.

In your custom renderCell function, you can call up the inheritance
chain if you want to extend default capabilities, or not. In each case,
you would then return a cell.

Given that you want to apply this to every cell, you might prefer to
define a column plugin and apply it to every column...

e.g.


//
define([
        "put-selector/put"
], function (put) {
        return function (column) {
                column.renderCell = function (object, value, cell) {
                        var cellNode = this.inherited(arguments)
                        var tooltip = put(cellNode, "div.tooltip"),
                        // Do something interesting
                        return cellNode;
                };
                return column;
        };
});

And then in the columns that you want to have a tooltip:

var grid = new Grid({
        columns: {
                foo: "Foo", // no tooltip
                bar: tooltip({ label: "Bar" })
        }
}, "someNodeId");

Where tooltip is your local reference to your column plugin.

Is there a specific reason you want to extend defaultRenderCell?

Regards,
- -Dylan

on 12/4/13 8:41 AM (GMT-07:00) Michael Schall said the following:
> I'm attempting to override or add functionality the defaultRenderCell.
>  My goal is to have a tooltip (html title attribute) added to each cell,
> showing the (formatted) value in the cell.  Looking at the source of
> Grid.js, it seems that I should be able to add an aspect.after call
> somehow to defaultRenderCell.  Something like the following:
>
>   var CustomGrid = declare([OnDemandGrid, Keyboard, Selection,
> ColumnResizer, DijitRegistry]);
>   aspect.after(CustomGrid, "defaultRenderCell", function (object, data,
> td, options) {
>         td.title = td.innerHTML;
>   });
>
> Debugging the code, CustomGrid.defaultRenderCell == null, so I'm doing
> something wrong.
>
> From the comment in Grid.js,
>
>   // expose appendIfNode and default implementation of renderCell,
>   // e.g. for use by column plugins
>   Grid.appendIfNode = appendIfNode;
>   Grid.defaultRenderCell = defaultRenderCell;
>
> it looks like this is supposed to be exposed.
>
> Can someone give me an example of how defaultRenderCell can be
> overridden/hooked?
>
> Thanks
>
> Mike
>
> ________________________________________________________
> Dojo Toolkit: http://dojotoolkit.org/
> Tutorials: http://dojotoolkit.org/documentation/
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
>
> [hidden email]
> To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlKfW+UACgkQ1E2HcBNypM4dvwCgloJkXIwfzQfXGIsgKSwth7Yf
3HEAnjROe4Ia2+Q+3xxwxSgLKPjPLVGL
=8hmU
-----END PGP SIGNATURE-----
________________________________________________________
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


________________________________________________________
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: overriding/hooking dgrid's defaultRenderCell

dylanks
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Note that defaultRenderCell isn't actually a method on the Grid object.
Instead it's a function that gets called in the context of a Column.

        defaultRenderCell.call(column, object, data, td, options);

That's why aspect.after doesn't work for it.

You might want to aspect.after on the renderRow method, and do something
like:

aspect.after(CustomGrid, "renderRow", function(){
        // do something to iterate over each item in the rendered row
        // to add a tooltip to each cell
});

I was thinking it might make sense to do something like this:

var CustomGrid = new declare([OnDemandGrid, Keyboard, Selection,
ColumnResizer, DijitRegistry],
        {
                defaultRenderCell: function(object, data, td, options){
                // replace with the logic you want
                // unfortunately, defaultRenderCell doesn't return
                // a cell that you can easily extend
        }
});

But this approach is flawed for the same reasons that aspect.after won't
work, I think.

Given the proposed use case, I think this is a candidate for something
to refactor, to provide a hook to make it easier to extend the
defaultRenderCell method.

Perhaps Ken Franqueiro has some thoughts on what would be more efficient
here?

Regards,
- -Dylan

on 12/4/13 10:11 AM (GMT-07:00) Michael Schall said the following:

> Dylan -
>
> As you have suggested, I have currently specified the renderCell on a
> couple of my columns using the following code:
>
>     { field: "message", label: "Message",
>         renderCell: function(object, value, node, options){
>             node.title = value;
>             domConstruct.place(document.createTextNode(value), node);
>         }},
>
> We have large applications (500+ screens) that will potentially be moved
> to dgrid.  Our current homegrown grid implementation adds a tooltip for
> every column by default unless overridden.  My goal is to get dgrid to
> act the same way.  By default, add the tooltip, if you specify a
> renderCell, you are on your own to add it back in.  I like to not
> require my developers have to add this code to every column in our
> application.  
>
> I found the defaultRenderCell function and thought this was the perfect
> place to hook in so the developer would get the desired result without
> any code.
>
> Thanks for the quick response!
>
>  
>
>
> On Wed, Dec 4, 2013 at 10:44 AM, Dylan Schiemann <[hidden email]
> <mailto:[hidden email]>> wrote:
>
> The more typical pattern would be to add a renderCell method to your
> column definition.
>
> If dgrid finds either a renderCell or formatter on your column, it will
> ignored the defaultRenderCell method.
>
> In your custom renderCell function, you can call up the inheritance
> chain if you want to extend default capabilities, or not. In each case,
> you would then return a cell.
>
> Given that you want to apply this to every cell, you might prefer to
> define a column plugin and apply it to every column...
>
> e.g.
>
>
> //
> define([
>         "put-selector/put"
> ], function (put) {
>         return function (column) {
>                 column.renderCell = function (object, value, cell) {
>                         var cellNode = this.inherited(arguments)
>                         var tooltip = put(cellNode, "div.tooltip"),
>                         // Do something interesting
>                         return cellNode;
>                 };
>                 return column;
>         };
> });
>
> And then in the columns that you want to have a tooltip:
>
> var grid = new Grid({
>         columns: {
>                 foo: "Foo", // no tooltip
>                 bar: tooltip({ label: "Bar" })
>         }
> }, "someNodeId");
>
> Where tooltip is your local reference to your column plugin.
>
> Is there a specific reason you want to extend defaultRenderCell?
>
> Regards,
> -Dylan
>
> on 12/4/13 8:41 AM (GMT-07:00) Michael Schall said the following:
>> I'm attempting to override or add functionality the defaultRenderCell.
>>  My goal is to have a tooltip (html title attribute) added to each
> cell,
>> showing the (formatted) value in the cell.  Looking at the source of
>> Grid.js, it seems that I should be able to add an aspect.after call
>> somehow to defaultRenderCell.  Something like the following:
>
>>   var CustomGrid = declare([OnDemandGrid, Keyboard, Selection,
>> ColumnResizer, DijitRegistry]);
>>   aspect.after(CustomGrid, "defaultRenderCell", function (object,
> data,
>> td, options) {
>>         td.title = td.innerHTML;
>>   });
>
>> Debugging the code, CustomGrid.defaultRenderCell == null, so I'm doing
>> something wrong.
>
>> From the comment in Grid.js,
>
>>   // expose appendIfNode and default implementation of renderCell,
>>   // e.g. for use by column plugins
>>   Grid.appendIfNode = appendIfNode;
>>   Grid.defaultRenderCell = defaultRenderCell;
>
>> it looks like this is supposed to be exposed.
>
>> Can someone give me an example of how defaultRenderCell can be
>> overridden/hooked?
>
>> Thanks
>
>> Mike
>
>> ________________________________________________________
>> Dojo Toolkit: http://dojotoolkit.org/
>> Tutorials: http://dojotoolkit.org/documentation/
>> Reference Guide: http://dojotoolkit.org/reference-guide
>> API Documentation: http://dojotoolkit.org/api
>
>> [hidden email]
> <mailto:[hidden email]>
>> To unsubscribe, visit:
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     ________________________________________________________
>     Dojo Toolkit: http://dojotoolkit.org/
>     Tutorials: http://dojotoolkit.org/documentation/
>     Reference Guide: http://dojotoolkit.org/reference-guide
>     API Documentation: http://dojotoolkit.org/api
>
>     [hidden email]
>     <mailto:[hidden email]>
>     To unsubscribe, visit:
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
> ________________________________________________________
> Dojo Toolkit: http://dojotoolkit.org/
> Tutorials: http://dojotoolkit.org/documentation/
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
>
> [hidden email]
> To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlKfdjAACgkQ1E2HcBNypM4z5ACfVEaVOVUIcpQORoVr6MrWPtH9
iH0AnRcEQ0vEdhTxsHbojDsFBZz24tOc
=rjpk
-----END PGP SIGNATURE-----
________________________________________________________
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Co-Founder, Dojo Toolkit
CEO, SitePen, Inc.  http://www.sitepen.com/
Reply | Threaded
Open this post in threaded view
|

Re: overriding/hooking dgrid's defaultRenderCell

Kenneth G. Franqueiro
Yes, exposing defaultRenderCell in a way that makes it extensible is
something that we plan to add in a future release.

That said, in the interim it shouldn't be terribly hard to iterate over
a given column structure and apply a renderCell function to each column
as part of an extension (probably extending the _configColumn method).

--Ken

On 12/4/2013 1:36 PM, Dylan Schiemann wrote:

> Note that defaultRenderCell isn't actually a method on the Grid object.
> Instead it's a function that gets called in the context of a Column.
>
> defaultRenderCell.call(column, object, data, td, options);
>
> That's why aspect.after doesn't work for it.
>
> You might want to aspect.after on the renderRow method, and do something
> like:
>
> aspect.after(CustomGrid, "renderRow", function(){
> // do something to iterate over each item in the rendered row
> // to add a tooltip to each cell
> });
>
> I was thinking it might make sense to do something like this:
>
> var CustomGrid = new declare([OnDemandGrid, Keyboard, Selection,
> ColumnResizer, DijitRegistry],
> {
> defaultRenderCell: function(object, data, td, options){
> // replace with the logic you want
> // unfortunately, defaultRenderCell doesn't return
> // a cell that you can easily extend
> }
> });
>
> But this approach is flawed for the same reasons that aspect.after won't
> work, I think.
>
> Given the proposed use case, I think this is a candidate for something
> to refactor, to provide a hook to make it easier to extend the
> defaultRenderCell method.
>
> Perhaps Ken Franqueiro has some thoughts on what would be more efficient
> here?
>
> Regards,
> -Dylan
>
> on 12/4/13 10:11 AM (GMT-07:00) Michael Schall said the following:
>> Dylan -
>
>> As you have suggested, I have currently specified the renderCell on a
>> couple of my columns using the following code:
>
>>     { field: "message", label: "Message",
>>         renderCell: function(object, value, node, options){
>>             node.title = value;
>>             domConstruct.place(document.createTextNode(value), node);
>>         }},
>
>> We have large applications (500+ screens) that will potentially be moved
>> to dgrid.  Our current homegrown grid implementation adds a tooltip for
>> every column by default unless overridden.  My goal is to get dgrid to
>> act the same way.  By default, add the tooltip, if you specify a
>> renderCell, you are on your own to add it back in.  I like to not
>> require my developers have to add this code to every column in our
>> application.  
>
>> I found the defaultRenderCell function and thought this was the perfect
>> place to hook in so the developer would get the desired result without
>> any code.
>
>> Thanks for the quick response!
>
>
>
>
>> On Wed, Dec 4, 2013 at 10:44 AM, Dylan Schiemann <[hidden email]
>> <mailto:[hidden email]>> wrote:
>
>> The more typical pattern would be to add a renderCell method to your
>> column definition.
>
>> If dgrid finds either a renderCell or formatter on your column, it will
>> ignored the defaultRenderCell method.
>
>> In your custom renderCell function, you can call up the inheritance
>> chain if you want to extend default capabilities, or not. In each case,
>> you would then return a cell.
>
>> Given that you want to apply this to every cell, you might prefer to
>> define a column plugin and apply it to every column...
>
>> e.g.
>
>
>> //
>> define([
>>         "put-selector/put"
>> ], function (put) {
>>         return function (column) {
>>                 column.renderCell = function (object, value, cell) {
>>                         var cellNode = this.inherited(arguments)
>>                         var tooltip = put(cellNode, "div.tooltip"),
>>                         // Do something interesting
>>                         return cellNode;
>>                 };
>>                 return column;
>>         };
>> });
>
>> And then in the columns that you want to have a tooltip:
>
>> var grid = new Grid({
>>         columns: {
>>                 foo: "Foo", // no tooltip
>>                 bar: tooltip({ label: "Bar" })
>>         }
>> }, "someNodeId");
>
>> Where tooltip is your local reference to your column plugin.
>
>> Is there a specific reason you want to extend defaultRenderCell?
>
>> Regards,
>> -Dylan
>
>> on 12/4/13 8:41 AM (GMT-07:00) Michael Schall said the following:
>>> I'm attempting to override or add functionality the defaultRenderCell.
>>>  My goal is to have a tooltip (html title attribute) added to each
>> cell,
>>> showing the (formatted) value in the cell.  Looking at the source of
>>> Grid.js, it seems that I should be able to add an aspect.after call
>>> somehow to defaultRenderCell.  Something like the following:
>
>>>   var CustomGrid = declare([OnDemandGrid, Keyboard, Selection,
>>> ColumnResizer, DijitRegistry]);
>>>   aspect.after(CustomGrid, "defaultRenderCell", function (object,
>> data,
>>> td, options) {
>>>         td.title = td.innerHTML;
>>>   });
>
>>> Debugging the code, CustomGrid.defaultRenderCell == null, so I'm doing
>>> something wrong.
>
>>> From the comment in Grid.js,
>
>>>   // expose appendIfNode and default implementation of renderCell,
>>>   // e.g. for use by column plugins
>>>   Grid.appendIfNode = appendIfNode;
>>>   Grid.defaultRenderCell = defaultRenderCell;
>
>>> it looks like this is supposed to be exposed.
>
>>> Can someone give me an example of how defaultRenderCell can be
>>> overridden/hooked?
>
>>> Thanks
>
>>> Mike
>
>>> ________________________________________________________
>>> Dojo Toolkit: http://dojotoolkit.org/
>>> Tutorials: http://dojotoolkit.org/documentation/
>>> Reference Guide: http://dojotoolkit.org/reference-guide
>>> API Documentation: http://dojotoolkit.org/api
>
>>> [hidden email]
>> <mailto:[hidden email]>
>>> To unsubscribe, visit:
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>     ________________________________________________________
>>     Dojo Toolkit: http://dojotoolkit.org/
>>     Tutorials: http://dojotoolkit.org/documentation/
>>     Reference Guide: http://dojotoolkit.org/reference-guide
>>     API Documentation: http://dojotoolkit.org/api
>
>>     [hidden email]
>>     <mailto:[hidden email]>
>>     To unsubscribe, visit:
>>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>> ________________________________________________________
>> Dojo Toolkit: http://dojotoolkit.org/
>> Tutorials: http://dojotoolkit.org/documentation/
>> Reference Guide: http://dojotoolkit.org/reference-guide
>> API Documentation: http://dojotoolkit.org/api
>
>> [hidden email]
>> To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
> ________________________________________________________
> Dojo Toolkit: http://dojotoolkit.org/
> Tutorials: http://dojotoolkit.org/documentation/
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
>
> [hidden email]
> To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
________________________________________________________
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: overriding/hooking dgrid's defaultRenderCell

Michael Schall
Has the feature to allow an extension to easily override defaultRenderCell been added?  I'm still having issues trying to override it.  Is there a better "current" solution?  Providing a renderCell function seems like a huge hammer! :)


On Wed, Dec 4, 2013 at 1:09 PM, Kenneth G. Franqueiro <[hidden email]> wrote:
Yes, exposing defaultRenderCell in a way that makes it extensible is
something that we plan to add in a future release.

That said, in the interim it shouldn't be terribly hard to iterate over
a given column structure and apply a renderCell function to each column
as part of an extension (probably extending the _configColumn method).

--Ken

On 12/4/2013 1:36 PM, Dylan Schiemann wrote:
> Note that defaultRenderCell isn't actually a method on the Grid object.
> Instead it's a function that gets called in the context of a Column.
>
>       defaultRenderCell.call(column, object, data, td, options);
>
> That's why aspect.after doesn't work for it.
>
> You might want to aspect.after on the renderRow method, and do something
> like:
>
> aspect.after(CustomGrid, "renderRow", function(){
>       // do something to iterate over each item in the rendered row
>       // to add a tooltip to each cell
> });
>
> I was thinking it might make sense to do something like this:
>
> var CustomGrid = new declare([OnDemandGrid, Keyboard, Selection,
> ColumnResizer, DijitRegistry],
>       {
>               defaultRenderCell: function(object, data, td, options){
>               // replace with the logic you want
>               // unfortunately, defaultRenderCell doesn't return
>               // a cell that you can easily extend
>       }
> });
>
> But this approach is flawed for the same reasons that aspect.after won't
> work, I think.
>
> Given the proposed use case, I think this is a candidate for something
> to refactor, to provide a hook to make it easier to extend the
> defaultRenderCell method.
>
> Perhaps Ken Franqueiro has some thoughts on what would be more efficient
> here?
>
> Regards,
> -Dylan
>
> on 12/4/13 10:11 AM (GMT-07:00) Michael Schall said the following:
>> Dylan -
>
>> As you have suggested, I have currently specified the renderCell on a
>> couple of my columns using the following code:
>
>>     { field: "message", label: "Message",
>>         renderCell: function(object, value, node, options){
>>             node.title = value;
>>             domConstruct.place(document.createTextNode(value), node);
>>         }},
>
>> We have large applications (500+ screens) that will potentially be moved
>> to dgrid.  Our current homegrown grid implementation adds a tooltip for
>> every column by default unless overridden.  My goal is to get dgrid to
>> act the same way.  By default, add the tooltip, if you specify a
>> renderCell, you are on your own to add it back in.  I like to not
>> require my developers have to add this code to every column in our
>> application.
>
>> I found the defaultRenderCell function and thought this was the perfect
>> place to hook in so the developer would get the desired result without
>> any code.
>
>> Thanks for the quick response!
>
>
>
>
>> On Wed, Dec 4, 2013 at 10:44 AM, Dylan Schiemann <[hidden email]
>> <mailto:[hidden email]>> wrote:
>
>> The more typical pattern would be to add a renderCell method to your
>> column definition.
>
>> If dgrid finds either a renderCell or formatter on your column, it will
>> ignored the defaultRenderCell method.
>
>> In your custom renderCell function, you can call up the inheritance
>> chain if you want to extend default capabilities, or not. In each case,
>> you would then return a cell.
>
>> Given that you want to apply this to every cell, you might prefer to
>> define a column plugin and apply it to every column...
>
>> e.g.
>
>
>> //
>> define([
>>         "put-selector/put"
>> ], function (put) {
>>         return function (column) {
>>                 column.renderCell = function (object, value, cell) {
>>                         var cellNode = this.inherited(arguments)
>>                         var tooltip = put(cellNode, "div.tooltip"),
>>                         // Do something interesting
>>                         return cellNode;
>>                 };
>>                 return column;
>>         };
>> });
>
>> And then in the columns that you want to have a tooltip:
>
>> var grid = new Grid({
>>         columns: {
>>                 foo: "Foo", // no tooltip
>>                 bar: tooltip({ label: "Bar" })
>>         }
>> }, "someNodeId");
>
>> Where tooltip is your local reference to your column plugin.
>
>> Is there a specific reason you want to extend defaultRenderCell?
>
>> Regards,
>> -Dylan
>
>> on 12/4/13 8:41 AM (GMT-07:00) Michael Schall said the following:
>>> I'm attempting to override or add functionality the defaultRenderCell.
>>>  My goal is to have a tooltip (html title attribute) added to each
>> cell,
>>> showing the (formatted) value in the cell.  Looking at the source of
>>> Grid.js, it seems that I should be able to add an aspect.after call
>>> somehow to defaultRenderCell.  Something like the following:
>
>>>   var CustomGrid = declare([OnDemandGrid, Keyboard, Selection,
>>> ColumnResizer, DijitRegistry]);
>>>   aspect.after(CustomGrid, "defaultRenderCell", function (object,
>> data,
>>> td, options) {
>>>         td.title = td.innerHTML;
>>>   });
>
>>> Debugging the code, CustomGrid.defaultRenderCell == null, so I'm doing
>>> something wrong.
>
>>> From the comment in Grid.js,
>
>>>   // expose appendIfNode and default implementation of renderCell,
>>>   // e.g. for use by column plugins
>>>   Grid.appendIfNode = appendIfNode;
>>>   Grid.defaultRenderCell = defaultRenderCell;
>
>>> it looks like this is supposed to be exposed.
>
>>> Can someone give me an example of how defaultRenderCell can be
>>> overridden/hooked?
>
>>> Thanks
>
>>> Mike
>
>>> ________________________________________________________
>>> Dojo Toolkit: http://dojotoolkit.org/
>>> Tutorials: http://dojotoolkit.org/documentation/
>>> Reference Guide: http://dojotoolkit.org/reference-guide
>>> API Documentation: http://dojotoolkit.org/api
>
>>> [hidden email]
>> <mailto:[hidden email]>
>>> To unsubscribe, visit:
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>     ________________________________________________________
>>     Dojo Toolkit: http://dojotoolkit.org/
>>     Tutorials: http://dojotoolkit.org/documentation/
>>     Reference Guide: http://dojotoolkit.org/reference-guide
>>     API Documentation: http://dojotoolkit.org/api
>
>>     [hidden email]
>>     <mailto:[hidden email]>
>>     To unsubscribe, visit:
>>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>> ________________________________________________________
>> Dojo Toolkit: http://dojotoolkit.org/
>> Tutorials: http://dojotoolkit.org/documentation/
>> Reference Guide: http://dojotoolkit.org/reference-guide
>> API Documentation: http://dojotoolkit.org/api
>
>> [hidden email]
>> To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
> ________________________________________________________
> Dojo Toolkit: http://dojotoolkit.org/
> Tutorials: http://dojotoolkit.org/documentation/
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
>
> [hidden email]
> To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
________________________________________________________
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: overriding/hooking dgrid's defaultRenderCell

Kenneth G. Franqueiro
Yes, since late 2014; see "Grid.defaultRenderCell moved to prototype" in
the 0.4.0 release notes:
https://github.com/SitePen/dgrid/releases/tag/v0.4.0

--Ken

On 3/15/2016 6:08 PM, Michael Schall wrote:

> Has the feature to allow an extension to easily override
> defaultRenderCell been added?  I'm still having issues trying to
> override it.  Is there a better "current" solution?  Providing a
> renderCell function seems like a huge hammer! :)
>
>
> On Wed, Dec 4, 2013 at 1:09 PM, Kenneth G. Franqueiro
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     Yes, exposing defaultRenderCell in a way that makes it extensible is
>     something that we plan to add in a future release.
>
>     That said, in the interim it shouldn't be terribly hard to iterate over
>     a given column structure and apply a renderCell function to each column
>     as part of an extension (probably extending the _configColumn method).
>
>     --Ken
>
>     On 12/4/2013 1:36 PM, Dylan Schiemann wrote:
>     > Note that defaultRenderCell isn't actually a method on the Grid
>     object.
>     > Instead it's a function that gets called in the context of a Column.
>     >
>     >       defaultRenderCell.call(column, object, data, td, options);
>     >
>     > That's why aspect.after doesn't work for it.
>     >
>     > You might want to aspect.after on the renderRow method, and do
>     something
>     > like:
>     >
>     > aspect.after(CustomGrid, "renderRow", function(){
>     >       // do something to iterate over each item in the rendered row
>     >       // to add a tooltip to each cell
>     > });
>     >
>     > I was thinking it might make sense to do something like this:
>     >
>     > var CustomGrid = new declare([OnDemandGrid, Keyboard, Selection,
>     > ColumnResizer, DijitRegistry],
>     >       {
>     >               defaultRenderCell: function(object, data, td, options){
>     >               // replace with the logic you want
>     >               // unfortunately, defaultRenderCell doesn't return
>     >               // a cell that you can easily extend
>     >       }
>     > });
>     >
>     > But this approach is flawed for the same reasons that aspect.after
>     won't
>     > work, I think.
>     >
>     > Given the proposed use case, I think this is a candidate for something
>     > to refactor, to provide a hook to make it easier to extend the
>     > defaultRenderCell method.
>     >
>     > Perhaps Ken Franqueiro has some thoughts on what would be more
>     efficient
>     > here?
>     >
>     > Regards,
>     > -Dylan
>     >
>     > on 12/4/13 10:11 AM (GMT-07:00) Michael Schall said the following:
>     >> Dylan -
>     >
>     >> As you have suggested, I have currently specified the renderCell on a
>     >> couple of my columns using the following code:
>     >
>     >>     { field: "message", label: "Message",
>     >>         renderCell: function(object, value, node, options){
>     >>             node.title = value;
>     >>             domConstruct.place(document.createTextNode(value), node);
>     >>         }},
>     >
>     >> We have large applications (500+ screens) that will potentially
>     be moved
>     >> to dgrid.  Our current homegrown grid implementation adds a
>     tooltip for
>     >> every column by default unless overridden.  My goal is to get
>     dgrid to
>     >> act the same way.  By default, add the tooltip, if you specify a
>     >> renderCell, you are on your own to add it back in.  I like to not
>     >> require my developers have to add this code to every column in our
>     >> application.
>     >
>     >> I found the defaultRenderCell function and thought this was the
>     perfect
>     >> place to hook in so the developer would get the desired result
>     without
>     >> any code.
>     >
>     >> Thanks for the quick response!
>     >
>     >
>     >
>     >
>     >> On Wed, Dec 4, 2013 at 10:44 AM, Dylan Schiemann
>     <[hidden email] <mailto:[hidden email]>
>     >> <mailto:[hidden email] <mailto:[hidden email]>>> wrote:
>     >
>     >> The more typical pattern would be to add a renderCell method to your
>     >> column definition.
>     >
>     >> If dgrid finds either a renderCell or formatter on your column,
>     it will
>     >> ignored the defaultRenderCell method.
>     >
>     >> In your custom renderCell function, you can call up the inheritance
>     >> chain if you want to extend default capabilities, or not. In each
>     case,
>     >> you would then return a cell.
>     >
>     >> Given that you want to apply this to every cell, you might prefer to
>     >> define a column plugin and apply it to every column...
>     >
>     >> e.g.
>     >
>     >
>     >> //
>     >> define([
>     >>         "put-selector/put"
>     >> ], function (put) {
>     >>         return function (column) {
>     >>                 column.renderCell = function (object, value, cell) {
>     >>                         var cellNode = this.inherited(arguments)
>     >>                         var tooltip = put(cellNode, "div.tooltip"),
>     >>                         // Do something interesting
>     >>                         return cellNode;
>     >>                 };
>     >>                 return column;
>     >>         };
>     >> });
>     >
>     >> And then in the columns that you want to have a tooltip:
>     >
>     >> var grid = new Grid({
>     >>         columns: {
>     >>                 foo: "Foo", // no tooltip
>     >>                 bar: tooltip({ label: "Bar" })
>     >>         }
>     >> }, "someNodeId");
>     >
>     >> Where tooltip is your local reference to your column plugin.
>     >
>     >> Is there a specific reason you want to extend defaultRenderCell?
>     >
>     >> Regards,
>     >> -Dylan
>     >
>     >> on 12/4/13 8:41 AM (GMT-07:00) Michael Schall said the following:
>     >>> I'm attempting to override or add functionality the
>     defaultRenderCell.
>     >>>  My goal is to have a tooltip (html title attribute) added to each
>     >> cell,
>     >>> showing the (formatted) value in the cell.  Looking at the source of
>     >>> Grid.js, it seems that I should be able to add an aspect.after call
>     >>> somehow to defaultRenderCell.  Something like the following:
>     >
>     >>>   var CustomGrid = declare([OnDemandGrid, Keyboard, Selection,
>     >>> ColumnResizer, DijitRegistry]);
>     >>>   aspect.after(CustomGrid, "defaultRenderCell", function (object,
>     >> data,
>     >>> td, options) {
>     >>>         td.title = td.innerHTML;
>     >>>   });
>     >
>     >>> Debugging the code, CustomGrid.defaultRenderCell == null, so I'm
>     doing
>     >>> something wrong.
>     >
>     >>> From the comment in Grid.js,
>     >
>     >>>   // expose appendIfNode and default implementation of renderCell,
>     >>>   // e.g. for use by column plugins
>     >>>   Grid.appendIfNode = appendIfNode;
>     >>>   Grid.defaultRenderCell = defaultRenderCell;
>     >
>     >>> it looks like this is supposed to be exposed.
>     >
>     >>> Can someone give me an example of how defaultRenderCell can be
>     >>> overridden/hooked?
>     >
>     >>> Thanks
>     >
>     >>> Mike
>     >
>     >>> ________________________________________________________
>     >>> Dojo Toolkit: http://dojotoolkit.org/
>     >>> Tutorials: http://dojotoolkit.org/documentation/
>     >>> Reference Guide: http://dojotoolkit.org/reference-guide
>     >>> API Documentation: http://dojotoolkit.org/api
>     >
>     >>> [hidden email]
>     <mailto:[hidden email]>
>     >> <mailto:[hidden email]
>     <mailto:[hidden email]>>
>     >>> To unsubscribe, visit:
>     >> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >>     ________________________________________________________
>     >>     Dojo Toolkit: http://dojotoolkit.org/
>     >>     Tutorials: http://dojotoolkit.org/documentation/
>     >>     Reference Guide: http://dojotoolkit.org/reference-guide
>     >>     API Documentation: http://dojotoolkit.org/api
>     >
>     >>     [hidden email]
>     <mailto:[hidden email]>
>     >>     <mailto:[hidden email]
>     <mailto:[hidden email]>>
>     >>     To unsubscribe, visit:
>     >>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >
>     >
>     >> ________________________________________________________
>     >> Dojo Toolkit: http://dojotoolkit.org/
>     >> Tutorials: http://dojotoolkit.org/documentation/
>     >> Reference Guide: http://dojotoolkit.org/reference-guide
>     >> API Documentation: http://dojotoolkit.org/api
>     >
>     >> [hidden email]
>     <mailto:[hidden email]>
>     >> To unsubscribe, visit:
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     > ________________________________________________________
>     > Dojo Toolkit: http://dojotoolkit.org/
>     > Tutorials: http://dojotoolkit.org/documentation/
>     > Reference Guide: http://dojotoolkit.org/reference-guide
>     > API Documentation: http://dojotoolkit.org/api
>     >
>     > [hidden email]
>     <mailto:[hidden email]>
>     > To unsubscribe, visit:
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>     >
>     ________________________________________________________
>     Dojo Toolkit: http://dojotoolkit.org/
>     Tutorials: http://dojotoolkit.org/documentation/
>     Reference Guide: http://dojotoolkit.org/reference-guide
>     API Documentation: http://dojotoolkit.org/api
>
>     [hidden email]
>     <mailto:[hidden email]>
>     To unsubscribe, visit:
>     http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>
>
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest