Forum
Topic RSS
10:04
25/06/2011
OfflineHi --
Hoping someone here can help me figure out what I'm doing wrong. I have a script snippet in a view file in my ASP.NET MVC 3 app that is attempting to wrap a call to the jqGrid function inside of a call to another function so that I can install some custom handlers on a more global basis and not just on each individual instance. Let me explain what I mean.
Here's the code snippet before I make any changes to it (which by the way works fine):
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table id="blogsList" class="scroll" cellpadding="0" cellspacing="0">
</table>
<div id="blogsPager" class="scroll" style="text-align: center;">
</div>
<script type="text/javascript">
$().ready(function () {
$("#blogsList").jqGrid( {
url: './Blogs/BlogsGridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['', '', 'Title', 'Posted On'],
colModel: [
{ name: 'Edit', index: 'Edit', width: 80, align: 'left', sortable: false },
{ name: 'Delete', index: 'Delete', width: 80, align: 'left', sortable: false },
{ name: 'Title', index: 'Title', width: 300, align: 'left' },
{ name: 'PostedOn', index: 'PostedOn', width: 100, align: 'left'}],
pager: $('#blogsPager'),
rowNum: 2,
rowList: [2, 5, 10, 20, 50],
sortname: 'PostedOn',
sortorder: "desc",
viewrecords: true,
caption: 'Blogs'
});
});
</script>
As I said, this works fine. Now in its own javascript file I have defined a function called jqGridDecorator and added it to the $.fn collection:
(function ($) {
$.fn.jqGridDecorator = function (params) {
// trying to figure out what to insert here
}
})(jQuery);
I would ideally like to replace the call to jqGrid in the first script snippet above with a call to this jqGridDecorator function and have this function turn around and call jqGrid itself applying it to the same target and passing the same parameters as the original call did. I would then follow this function call with an instruction to set the onSortCol property of the jqGrid to my own handler function. What I am after is a way to do this wrapping in one place and be as unobtrusive as possible in the actual grid instance call sites (ideally only replacing a call to jqGrid with a call to jqGridDecorator, but leaving everything else in the view file the same as it was).
Problem is, I can't for the life of me figure out what to put inside this function to make it work.
The "this" inside my decorator function doesn't refer to the proper context, so I can't do something like this.jqGrid(params) -- although it would have been very nice if I could.
I noticed that inside my decorator function this[0] does seem to refer to something that looks like what I need with an id of "blogslist", but I believe it's not the jquery element but rather the raw table element in the calling view file's HTML.
I tried passing in as an additional parameter to the function the actual object on which I originally called jqGrid (and on which I now call my own jqGridDecorator) -- wiith the call in the view file looking like this: $("#blogslist").jqGridDecorator($("#blogslist", { // same parameter object as original call }); Then inside my decorator function (with parameters of "(obj,params)") I tried a call that looked something like: obj.jqGrid(params) to make it as close to the original call as possible. No such luck. I tried $.fn.jqGridDecorator.apply(obj,params), but that didn't work either. I'm perplexed why I can't call the original jqGrid function just like I originally did, except from within my custom decorator function instead of from the view file's javascript code directly.
I'm running out of ideas, but I would like to be able to install the different sort handler behavior once and be done with it rather than having to reproduce it every time I create a grid.
Does anyone have any insights that might help me. Clearly something is wrong with the parameters I'm passing to the function or the ways inside the function that I've been trying to invoke the original jqGrid call.
Thanks very much. Hope this was remotely intelligble.
Regards,
Mike
Most Users Ever Online: 994
Currently Online:
16 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
Log In
Home