Forum



12:57

06/10/2009

It so happance that the application I have here have Row ID's with commas in them (example 1432,1433,1444 this is Single ID!)
The problem is that I ahve it in Multiseelct and I need to select spesific rows from outside the grid.
If I was using setSelection the Row was selected but not the Checkbox.
I ahve found the error, it's becouse jQuery get by ID cannt work with ID's like that.
here is My Fix:
setSelection : function(selection,onsr) {
return this.each(function(){
var $t = this, stat,pt, ner, ia, tpsr;
if(selection === undefined) { return; }
onsr = onsr === false ? false : true;
pt=$t.rows.namedItem(selection+"");
if(!pt) { return; }
function scrGrid(iR){
var ch = $($t.grid.bDiv)[0].clientHeight,
st = $($t.grid.bDiv)[0].scrollTop,
rpos = $t.rows[iR].offsetTop,
rh = $t.rows[iR].clientHeight;
if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
else if(rpos < ch+st) {
if(rpos < st) {
$($t.grid.bDiv)[0].scrollTop = rpos;
}
}
}
if($t.p.scrollrows===true) {
ner = $t.rows.namedItem(selection).rowIndex;
if(ner >=0 ){
scrGrid(ner);
}
}
if(!$t.p.multiselect) {
if(pt.className !== "ui-subgrid") {
if( $t.p.selrow ) {
$($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
}
$t.p.selrow = pt.id;
$(pt).addClass("ui-state-highlight").attr("aria-selected","true");
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, true); }
}
} else {
$t.p.selrow = pt.id;
ia = $.inArray($t.p.selrow,$t.p.selarrrow);
if ( ia === -1 ){
if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
stat = true;
$($(pt).find('input')).attr("checked",stat);
$t.p.selarrrow.push($t.p.selrow);
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, stat); }
} else {
if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
stat = false;
$($(pt).find('input')).attr("checked",stat);
$t.p.selarrrow.splice(ia,1);
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, stat); }
tpsr = $t.p.selarrrow[0];
$t.p.selrow = (tpsr === undefined) ? null : tpsr;
}
}
});
}
});
It's not perfect, since if you would have an input field in the row, that will be broken, but it's a good direction.
15:06

06/10/2009

In addition to the prevoiuse one, here is a fix with the reset selection fixed:
setSelection : function(selection,onsr) {
return this.each(function(){
var $t = this, stat,pt, ner, ia, tpsr;
if(selection === undefined) { return; }
onsr = onsr === false ? false : true;
pt=$t.rows.namedItem(selection+"");
if(!pt) { return; }
function scrGrid(iR){
var ch = $($t.grid.bDiv)[0].clientHeight,
st = $($t.grid.bDiv)[0].scrollTop,
rpos = $t.rows[iR].offsetTop,
rh = $t.rows[iR].clientHeight;
if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
else if(rpos < ch+st) {
if(rpos < st) {
$($t.grid.bDiv)[0].scrollTop = rpos;
}
}
}
if($t.p.scrollrows===true) {
ner = $t.rows.namedItem(selection).rowIndex;
if(ner >=0 ){
scrGrid(ner);
}
}
if(!$t.p.multiselect) {
if(pt.className !== "ui-subgrid") {
if( $t.p.selrow ) {
$($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
}
$t.p.selrow = pt.id;
$(pt).addClass("ui-state-highlight").attr("aria-selected","true");
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, true); }
}
} else {
$t.p.selrow = pt.id;
ia = $.inArray($t.p.selrow,$t.p.selarrrow);
if ( ia === -1 ){
if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
stat = true;
$($(pt).find('input')).attr("checked",stat);
$t.p.selarrrow.push($t.p.selrow);
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, stat); }
} else {
if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
stat = false;
$($(pt).find('input')).attr("checked",stat);
$t.p.selarrrow.splice(ia,1);
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, stat); }
tpsr = $t.p.selarrrow[0];
$t.p.selrow = (tpsr === undefined) ? null : tpsr;
}
}
});
},
resetSelection : function(){
return this.each(function(){
var t = this, ind;
if(!t.p.multiselect) {
if(t.p.selrow) {
$("#"+t.p.id+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
t.p.selrow = null;
}
} else {
$(t.p.selarrrow).each(function(i,n){
ind = t.rows.namedItem(n);
$(ind).removeClass("ui-state-highlight").attr("aria-selected","false");
$($(ind).find('input')).attr("checked",false);
});
$("#cb_"+$.jgrid.jqID(t.p.id)).attr("checked",false);
t.p.selarrrow = [];
}
t.p.savedRow = [];
});
}
});
Most Users Ever Online: 715
Currently Online:
61 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