kolli
03-20-2009, 10:49 AM
I have a requirement of multi cell select in a particular row of a grid. I tried setting the selection mode for cellselection model to MULTI but i couldnot find any difference.
So i wrote this piece of code and i am able to select multiple cells by pressing the shift key, It works fine except that the first clicked cell looses the selection.
import com.extjs.gxt.ui.client.core.El;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.widget.grid.CellSelectionModel;
import com.google.gwt.dom.client.Element;
public class RowCellSelectionModel<M extends ModelData> extends CellSelectionModel<M> {
int lastSelectedRow;
int lastSelectedCol;
@Override
protected void handleMouseDown(GridEvent e) {
if(e.colIndex ==0 )
return;
if(lastSelectedRow == 0)
{
selectCell(e.rowIndex, e.colIndex);
// grid.getView().focusCell(e.rowIndex, e.colIndex, true);
lastSelectedRow = e.rowIndex;
lastSelectedCol = e.colIndex;
}else if (lastSelectedRow == e.rowIndex)
{
if(e.isShiftKey())
{
for (int i = 0 ; i < store.getCount(); i++) {
Element cell = grid.getView().getCell(lastSelectedRow, i);
if (cell != null) {
El.fly(cell).removeStyleName("x-grid3-cell-selected");
}
}
if(lastSelectedCol > e.colIndex){
for (int iter = e.colIndex ; iter < lastSelectedCol +1 ; iter++)
{
Element cell = grid.getView().getCell(e.rowIndex, iter);
if (cell != null) {
El.fly(cell).addStyleName("x-grid3-cell-selected");
}
// grid.getView().focusCell(e.rowIndex, iter, true);
}
lastSelectedRow = e.rowIndex;
}else
{
for (int iter = lastSelectedCol; iter < e.colIndex + 1 ; iter++)
{
Element cell = grid.getView().getCell(e.rowIndex, iter);
if (cell != null) {
El.fly(cell).addStyleName("x-grid3-cell-selected");
}
// grid.getView().focusCell(e.rowIndex, iter, true);
}
lastSelectedRow = e.rowIndex;
// lastSelectedCol = e.colIndex;
}
}else
{
for (int i = 0 ; i < store.getCount(); i++)
{
Element cell = grid.getView().getCell(lastSelectedRow, i);
if (cell != null) {
El.fly(cell).removeStyleName("x-grid3-cell-selected");
}
}
selectCell(e.rowIndex, e.colIndex);
lastSelectedRow = e.rowIndex;
lastSelectedCol = e.colIndex;
}
}else
{
for (int i = 0 ; i < store.getCount(); i++)
{
Element cell = grid.getView().getCell(lastSelectedRow, i);
if (cell != null) {
El.fly(cell).removeStyleName("x-grid3-cell-selected");
}
}
selectCell(e.rowIndex, e.colIndex);
lastSelectedRow = e.rowIndex;
lastSelectedCol = e.colIndex;
}
super.handleMouseDown(e);
}
}
Am i doing something wrong??
So i wrote this piece of code and i am able to select multiple cells by pressing the shift key, It works fine except that the first clicked cell looses the selection.
import com.extjs.gxt.ui.client.core.El;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.widget.grid.CellSelectionModel;
import com.google.gwt.dom.client.Element;
public class RowCellSelectionModel<M extends ModelData> extends CellSelectionModel<M> {
int lastSelectedRow;
int lastSelectedCol;
@Override
protected void handleMouseDown(GridEvent e) {
if(e.colIndex ==0 )
return;
if(lastSelectedRow == 0)
{
selectCell(e.rowIndex, e.colIndex);
// grid.getView().focusCell(e.rowIndex, e.colIndex, true);
lastSelectedRow = e.rowIndex;
lastSelectedCol = e.colIndex;
}else if (lastSelectedRow == e.rowIndex)
{
if(e.isShiftKey())
{
for (int i = 0 ; i < store.getCount(); i++) {
Element cell = grid.getView().getCell(lastSelectedRow, i);
if (cell != null) {
El.fly(cell).removeStyleName("x-grid3-cell-selected");
}
}
if(lastSelectedCol > e.colIndex){
for (int iter = e.colIndex ; iter < lastSelectedCol +1 ; iter++)
{
Element cell = grid.getView().getCell(e.rowIndex, iter);
if (cell != null) {
El.fly(cell).addStyleName("x-grid3-cell-selected");
}
// grid.getView().focusCell(e.rowIndex, iter, true);
}
lastSelectedRow = e.rowIndex;
}else
{
for (int iter = lastSelectedCol; iter < e.colIndex + 1 ; iter++)
{
Element cell = grid.getView().getCell(e.rowIndex, iter);
if (cell != null) {
El.fly(cell).addStyleName("x-grid3-cell-selected");
}
// grid.getView().focusCell(e.rowIndex, iter, true);
}
lastSelectedRow = e.rowIndex;
// lastSelectedCol = e.colIndex;
}
}else
{
for (int i = 0 ; i < store.getCount(); i++)
{
Element cell = grid.getView().getCell(lastSelectedRow, i);
if (cell != null) {
El.fly(cell).removeStyleName("x-grid3-cell-selected");
}
}
selectCell(e.rowIndex, e.colIndex);
lastSelectedRow = e.rowIndex;
lastSelectedCol = e.colIndex;
}
}else
{
for (int i = 0 ; i < store.getCount(); i++)
{
Element cell = grid.getView().getCell(lastSelectedRow, i);
if (cell != null) {
El.fly(cell).removeStyleName("x-grid3-cell-selected");
}
}
selectCell(e.rowIndex, e.colIndex);
lastSelectedRow = e.rowIndex;
lastSelectedCol = e.colIndex;
}
super.handleMouseDown(e);
}
}
Am i doing something wrong??