There's no direct way that I can see.
You do get an onSelectAll event right after the rows have all been selected or all deselected – so you /could/ use that and deselect rows “after the fact” as it were. That would probably work.
Or, you could try something like $('#cb_jqg', $(mygrid)).hide() to hide the checkbox. The only problem there is that the id of the checkbox ('cb_jqg') is not documented – so it could change.
As an aside, I think it should be changed, because right now if you have two grids, both checkboxes have the same id. Everything seems to work – but its not supported by any standard. It would be better if each grid had a unique id for the checkbox.
Mark
However, I would still like to know how to click the minimize button via script.
Looks like $(“.ui-jqgrid-titlebar-close”, $(mygrid)).click() should do it…
Mark
Couldnt you use the formatCell or beforeEditCell event instead?
In case anyone tries to use it, the return condition should be:
if (!ptr.length || (td.tagName == 'INPUT' && !scb) || td.tagName == 'A') {
return true;
}
Mark
Im having problems with unformat and getRowData (using latest from github).
It looks to me like getRowData is broken, but perhaps Im missing something obvious.
getRowData calls: $.unformat($(this).html(),{colModel:$t.p.colModel},i)
Note, the first parameter is the html contents of the cell, as a string.
But $.unformat then uses $(cellval).text() – which for me is always returning the empty string (since, in general cellval wont be a selector that matches anything on the page!).
Im guessing that getRowData should just pass in this (it fixes the problem for me)
Mark
So following up to my own post… after studying the grid code I found a way to do it – although its something of a hack, and rather fragile.
If beforeSelectRow could be passed the event object, and the column ix, I think I could do everything I want without any trickery.
For anyone else interested in a grid that supports shift-click to select ranges, ctrl-click to toggle rows, and handles clicks on editable fields smartly, the code follows. To use it set “multiselect:true,beforeSelectRow:function(){return false;}” in the grid options, and then add the handler as follows:
$(mygrid).bind(“click”,$(mygrid),multiSelectHandler);
where multiselectHandler is:
function multiSelectHandler(e) {
var grid = e.data;
var ts = grid[0], td = e.target;
var scb = $(td).hasClass(“cbox”);
var ptr = $(td).parents(“tr.jqgrow”);
if (!ptr.length || td.tagName == 'INPUT' || td.tagName == 'A') {
return true;
}
var sel = grid.getGridParam('selarrrow');
var sid = ptr[0].id;
var selected = $.inArray(sid, sel) >= 0;
if (e.ctrlKey || (scb && (selected || !e.shiftKey))) {
grid.setSelection(false,true,ptr);
} else {
if (e.shiftKey) {
var six = grid.getInd( sid);
var min = six, max = six;
$.each(sel, function() {
var ix = grid.getInd( this);
if (ix < min) min = ix;
if (ix > max) max = ix;
});
while (min <= max) {
var row = ts.rows[min++];
var rid = row.id;
if (rid != sid && $.inArray(rid, sel)<0) {
grid.setSelection( false, false, $(row));
}
}
} else if (!selected) {
grid.resetSelection();
}
if (!selected) {
grid.setSelection( false, true, ptr);
} else {
var osr = grid.getGridParam('onSelectRow');
if ($.isFunction(osr)) {
osr(sid, true);
}
}
}
}
No – you express yourself very clearly. Apparently I dont 
If you look at my changes (better yet, try them out), you will see that existing code works *without any modification*.
In addition, you can use the new syntax ( $(selector).jqGrid(“method”,args) rather than $(selector).method(args) ). But its not required.
The only time users need to make a change is if they want to get rid of the old syntax, in order to prevent the existing namespace pollution.
In that case, they set $.jgrid.no_legacy_api=true, and then they *only* get the new syntax.
So once again – there is /no/ breakage of existing code with these changes.
And yes – of course there are many more functions that should be fixed – I just targetted grid.base.js to show you where I was going, and to see what you thought.
Mark
Sorry, you're right… except that there appears to be a minor bug in jQuery.
If you're setting height or width, and you pass in a -ve value, (eg $(“#foo”).css(“width”, “-4px”), then it goes through the “undefined” case in the above, which then /returns/ the width, rather than setting the width, and returning a jQuery.
That's what was happening, and I just jumped to the conclusion that css always returned a string.
So now I need to track down how colModel.width gets to be < 0. I think it has something to do with autowidth.
In any case, its probably my bug (in that it doesnt show up in firefox) – but I'd still say that its a good idea not to chain the css method when setting width/height by name unless you're certain the width/height is >= 0.
Mark
Not yet ready to test any of this, sorry, but I've looked over the changes.
Not much to say, except that I think its doing more or less what /I/ will want (once I get there!).
A couple of observations:
In grid.celledit.js, lines 119 and following:
|
1 |
<div id="LC119" class="line"> <span class="nx">nm</span> <span class="o">=</span> <span class="nx">$t</span><span class="p">.</span><span class="nx">p</span><span class="p">.</span><span class="nx">colModel</span><span class="p">[</span><span class="nx">iCol</span><span class="p">].</span><span class="nx">name</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'.'</span><span class="o">,</span><span class="s2">"\\."</span><span class="p">);</span></div><div id="LC120" class="line"> <span class="nx">switch</span> <span class="p">(</span><span class="nx">$t</span><span class="p">.</span><span class="nx">p</span><span class="p">.</span><span class="nx">colModel</span><span class="p">[</span><span class="nx">iCol</span><span class="p">].</span><span class="nx">edittype</span><span class="p">)</span> <span class="p">{</span></div><div id="LC121" class="line"> <span class="nx">case</span> <span class="s2">"select"</span><span class="o">:</span></div><div id="LC122" class="line"> <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">$t</span><span class="p">.</span><span class="nx">p</span><span class="p">.</span><span class="nx">colModel</span><span class="p">[</span><span class="nx">iCol</span><span class="p">].</span><span class="nx">editoptions</span><span class="p">.</span><span class="nx">multiple</span><span class="p">)</span> <span class="p">{</span></div><div id="LC123" class="line"> <span class="nx">v</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s2">"#"</span><span class="o">+</span><span class="nx">iRow</span><span class="o">+</span><span class="s2">"_"</span><span class="o">+</span><span class="nx">nm</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'.'</span><span class="o">,</span><span class="s2">"\\."</span><span class="p">)</span><span class="o">+</span><span class="s2">">option:selected"</span><span class="o">,</span><span class="nx">$t</span><span class="p">.</span><span class="nx">rows</span><span class="p">[</span><span class="nx">iRow</span><span class="p">]).</span><span class="nx">val</span><span class="p">();</span></div><div id="LC124" class="line"> <span class="nx">v2</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s2">"#"</span><span class="o">+</span><span class="nx">iRow</span><span class="o">+</span><span class="s2">"_"</span><span class="o">+</span><span class="nx">nm</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'.'</span><span class="o">,</span><span class="s2">"\\."</span><span class="p">)</span><span class="o">+</span><span class="s2">">option:selected"</span><span class="o">,</span><span class="nx">$t</span><span class="p">.</span><span class="nx">rows</span><span class="p">[</span><span class="nx">iRow</span><span class="p">]).</span><span class="nx">text</span><span class="p">();</span></div><div id="LC125" class="line"> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div id="LC126" class="line"> <span class="kd">var</span> <span class="nx">sel</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s2">"#"</span><span class="o">+</span><span class="nx">iRow</span><span class="o">+</span><span class="s2">"_"</span><span class="o">+</span><span class="nx">nm</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'.'</span><span class="o">,</span><span class="s2">"\\."</span><span class="p">)</span><span class="o">,</span><span class="nx">$t</span><span class="p">.</span><span class="nx">rows</span><span class="p">[</span><span class="nx">iRow</span><span class="p">])</span><span class="o">,</span> <span class="nx">selectedText</span> <span class="o">=</span> <span class="p">[];</span></div><div id="LC127" class="line"> <span class="nx">v</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">sel</span><span class="p">).</span><span class="nx">val</span><span class="p">();<br /><br />Im not sure - but those three nm.replace(</span><span class="s1">'.'</span><span class="o">,</span><span class="s2">"\\."</span><span class="p">)</span> look wrong, given the definition of nm...<br /><br />Also, this looks wrong:<br /><pre>if($t.p.colModel[iCol].formatter |
Hi Tony,
Yes – my solution doesnt (shouldnt!) break anything – unless the user explicitly asks for the old api to be removed.
I've modified 3.5.2, and put it at http://myosotissp.com/jqGrid-3.5.2x.tgz to show you exactly what Im thinking.
For this, Ive only moved the methods defined in grid.base.js, but I've rewritten all calls to those methods (from anywhere) to use the “new” syntax.
If you use this as a straight replacement for 3.5.2, any existing code should continue to work (mine does!). In addition you can write calls to any method defined in grid.base.js using the new syntax, eg:
Hi Tony,
Thanks for the feedback. Sorry to be so slow to respond – I didnt notice your post until now.
I've just looked at the changes, and as you say, its an improvement, but there's still a lot of names added to both $ and $.fn.
I realized my proposed solution – to extend $.fn.jqGrid rather than $.fn – doesnt quite work (after trying it out on one of the methods!), because when you call $(selection).jqGrid.showCol() (for example), showCol gets called, but with the wrong “this” parameter (the jqGrid object, rather than the jQuery object).
It looks like the “standard” way to do this in jQuery UI is to instead do something like $(selection).jqGrid(”showCol”).
I think we could achieve this by following the approach I outlined in my original post, and modifying $.fn.jqGrid to do something like:
if (typeof p == “string”) {
Isnt there an oversight in $.unformat? All the built in formatters are handled there, except for “select”.
Also, shouldn't there be an equivalent to getRowData that /does/ unformat the data (or did I miss it)? I would have expected it to be the default… the data gets formatted when its put into the grid, shouldnt it be unformatted when you take it out? Formatting is pure presentation – Im normally interested in the data value, rarely how its being displayed.
Mark
OlegK said:
Post edited 15:47 – 16/08/2009 by OlegK
Note that you can turn off caching via headers, and doing it this way has a significant advantage over the nd approach:
You can still use ETag to return a “304 Not Modified” response from the server. With the nd parameter you never get that opportunity.
Mark
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top