3.2.0

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
February 2,
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)
February 2,
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
February 6,

This topic is archived.

See also:


Back to support forum