fnRender friendly suggestion to return also JQuery objects
fnRender friendly suggestion to return also JQuery objects
jamjon3
Posts: 22Questions: 0Answers: 0
Under normal circumstances, you output a string and attach any events later such as....
[code]
{ "bSortable": false,"sClass": "SearchColumnDetails","bVisible": true,"mDataProp": "null", "fnRender":
function(oObj) {
return "";
}
},
[/code]
However, it would be super useful to be able to output a JQuery object with events and such already bound to it...
Something like:
[code]
{ "bSortable": false,"sClass": "SearchColumnDetails","bVisible": true,"mDataProp": "null", "fnRender":
function(oObj) {
return $("")
.button({
text: false,
icons: {
primary: "ui-icon-circle-triangle-e"
}
})
.click(function() {
alert('You added a click event to this button');
});
}
},
[/code]
Of course, you already helped me with that last nightly build (WORKS GREAT!!!!) but seemed like a good idea to share with you....
[code]
{ "bSortable": false,"sClass": "SearchColumnDetails","bVisible": true,"mDataProp": "null", "fnRender":
function(oObj) {
return "";
}
},
[/code]
However, it would be super useful to be able to output a JQuery object with events and such already bound to it...
Something like:
[code]
{ "bSortable": false,"sClass": "SearchColumnDetails","bVisible": true,"mDataProp": "null", "fnRender":
function(oObj) {
return $("")
.button({
text: false,
icons: {
primary: "ui-icon-circle-triangle-e"
}
})
.click(function() {
alert('You added a click event to this button');
});
}
},
[/code]
Of course, you already helped me with that last nightly build (WORKS GREAT!!!!) but seemed like a good idea to share with you....
This discussion has been closed.
Replies
Allan
But now we use JQuery's .live method to attach handlers to the returned from fnRender, so we can have whatever handlers we want applied automagically.
[code]
{ "sTitle": "Execute Action","sClass": "SearchColumn","bVisible": true,"mDataProp": null,"sDefaultContent":"", "fnRender":
function(oObj) {
var tempDiv = $(''),
executeActionsSelect = $('').appendTo(tempDiv);
$.each(self.administrationRuleChainsTab.data('ruleChains').executeActions.sort(function(a,b) { return (a.executeActionId - b.executeActionId); }),function() {
$('').val(this.executeActionId).html(this.executeActionId+" - "+this.name).appendTo(executeActionsSelect);
});
return tempDiv.remove().html();
}
},
[/code]
And then attaching the default selected value in the fnRowCallback along with the events. Hmmm....
[code]
function renderAssociation( obj ) { // handler for fnRender for certain columns
var value = obj.aData[obj.iDataColumn];
return '' + value + '\n';
}
/* apply handler to mouseover event for any .association that gets added to the DOM */
$('.association').live('mouseover', function(event) { /* do what you need */ }
[/code]
I'll take a closer look at them as I've used only .live sparingly and have been seeing .delegate mentioned more and more so I probably need to give them some more use in my coding.
As far as fnRender is concerned, I try to stay away from rendering raw HTML as a string as I've been sloppy in the past and missed closed tags and handling it in jquery keeps that straight but it would come in handy to just pass back a selector with an event already attached rather than the raw html text but in a lot of cases I would still handle it in the fnRowCallback.
I hope one day fnRender will support JQuery object ;)
[1]
http://www.datatables.net/forums/discussion/comment/15906
Allan
I am currently in a scenario where I need to return a JQuery object. In my case, however, I'd like to use an HTML5 Canvas to dynamically draw something in the cell as well as add additional bindings that take advantage of a closure from the context of the table's original creation.