Forum
November 2nd, 2014
A
A
A
The forums are currently locked and only available for read only access
Topic RSS
Returning jquery or dom elements from formatter functions
15/03/2012
21:43
21:43
evolr
Seattle, WA
New Member
Members
Forum Posts: 1
Member Since:
15/03/2012
15/03/2012
Offline
Supposing I have this in my colModel:
{ name: "foo", index: "food", formatter: myFormatter }
And then I have this method:
function myFormatter(cellValue, options, rowObject)
{
var img = $("<img />").attr("src", "foo.gif")
.click(function()
{
// do something...
// Note that all of the local vars are available to me as closures!! HUGE advantage!
});
// We're returning a jQuery object.
return img;
}
This does not currently work in jqgrid. I have a patched version of 3.8.2 that I edited to make it work, but it's not a terribly trivial edit, so upgrading to newer versions of jqgrid is difficult. This is a feature that others have asked for as well.
/blog/?page_id=393/feature-request/about-row-formatter/&value=jquery%20formatter&type=1&include=1&search=2
/blog/?page_id=393/feature-request/allow-custom-formatters-to-return-jquery-wrapped-dom-nodes/&value=jquery%20formatter&type=1&include=1&search=4
My edits were limited to grid.base.js (again, this was on version 3.8.2). I modified addJSONData (I didn't alter support for xml, because I don't use it). The main while loop in addJSONData() keeps calling rowData.push(...), where the "..." is a call to addCell(), which calls formatter() and formatCol(). I added checks in formatter() and formatCol() to see if the value returned is a jquery object ("obj instanceof jQuery"). addCell() performs a similar check, and in the case of a jQuery object, instead of returning a string: "<td>" + val + "</td>", it returns $("<td></td>").append(val).
It's not a ton of work, but it's annoying to edit the source file and create my own custom build each time I want to upgrade my jqgrid library. This would be so incredibly useful for all users!
Forum Timezone: Europe/Sofia
Most Users Ever Online: 715
Currently Online:
27 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66