:: Forum >>

Problem width remove row

Hi

Alex, compliments for your code ;-)
I have a little problem for remove row when user use sort in Grid.

This code run if user don't use sort:

function remove(robj,rdata) {
var i=0;
var j=0;
var nrow=robj.getRowCount(); //num rows
var srow=robj.getSelectionIndex(); //row selected

if (srow>=0 && srow < nrow ) {
for (i=0;i<nrow;i++)
{
if (i==srow) j++;
if (j!=0) rdata[i]=rdata[i+j];
}
robj.setRowCount(nrow-1);
//robj.setDataText(function(i, j){return rdata[i][j]});
robj.refresh();
}
}

Thare is another possibility for remove object ?

thank you in advenced


br1
Monday, February 2, 2004
When you run setRowCount - the row values array (the one which keeps row indices i.e. sort order) is re-initialised to 0..count-1 (and your previous sorting is lost). To avoid that - you need to retrieve current row/values array, remove your index from it and assign it back to row/values property.
Alex (ActiveWidgets)
Monday, February 2, 2004
Alex, thank you for your answer, i write this and run well.

---
function remove(robj) {
var srow = robj.getProperty("selection/index");
var nrow = robj.getProperty("row/count");
var thisRowB = robj.getProperty("row/values",nrow);
var thisRow=[];
var ind,k=0;
robj.setProperty("selection/index",-1);
if (nrow==1) thisRow='';
if (srow!=-1 && nrow>0)
{
for (i=0;i<nrow-1;i++)
{
if (thisRowB[i]==srow) {k++;ind=i}
thisRow[i]=thisRowB[i+k];
}
robj.setProperty("row/values",thisRow);
robj.setRowCount(nrow-k);
if (ind<nrow) robj.setProperty("selection/index",thisRow[ind]);
robj.refresh();
}
}
br1
Friday, February 6, 2004

This topic is archived.


Back to support forum

Forum search