:: Forum >> Version 2 >>

Multi Select

More information on this topic is available in the documentation section: /grid.doc.layout/.

I can not get the multi-select to accept a Shifted range to include all rows. For example, click on row 2, then press shift and click on row 5 should give me rows 2, 3, 4 and 5. I get 2 and 5 only.

Does anyone have this working correctly?
Steven Scott
Monday, June 19, 2006
No, this is still not implemented. Added this to the 'remaining bugs' list -

http://www.activewidgets.com/general.bugs/2-0-1.html
Alex (ActiveWidgets)
Monday, June 19, 2006
here is a simple workaround. it uses "onSelectorMouseDown ", you can alter this to "onRowMouseDown":

</head>
<
body>
    <
script>

    var 
obj = new AW.UI.Grid;
    
obj.setCellData("cell");
    
obj.setHeaderText("header");
    
obj.setColumnCount(10);
    
obj.setRowCount(10);
    
obj.setCellEditable(true);
    
obj.setSelectorVisible(true);
    
obj.setSelectorWidth(25);
    
obj.setSelectorText(function(i){return this.getRowPosition(i)+1});
    
obj.setSelectionMode("multi-row");

    Array.
prototype.max = function(){
        return 
Math.max.apply({},this)
    }

    Array.
prototype.min = function(){
        return 
Math.min.apply({},this)
    }

    
obj.onSelectorMouseDown = function(eventindex) {
        if (
event.shiftKey) {
            var 
selmin=obj.getSelectedRows().min();
            var 
rowmin Math.min(selmin,index);
            var 
rowmax Math.max(selmin,index);
            
selrows=[];
            for(
i=rowmini<=rowmaxi++){
                
selrows.push(i);
            }
            
obj.setSelectedRows(selrows);
        }
      };
    
/*
    obj.onRowMouseDown = function(event, index) {
        if (event.shiftKey) {
            var selmin=obj.getSelectedRows().min();
            var rowmin = Math.min(selmin,index);
            var rowmax = Math.max(selmin,index);
            selrows=[];
            for(i=rowmin; i<=rowmax; i++){
                selrows.push(i);
            }
            obj.setSelectedRows(selrows);
        }
      };
    */
    
document.write(obj);

    </
script>
<
br>
<
button value="getSelectedRows" onClick="alert(obj.getSelectedRows());">get Selected Rows</button>
</
body>
</
html
mono
Monday, June 26, 2006
Hi,
I've extended the previous workaround to get full functionality of select box. The function RemoveDuplicateValues is only called to cleanup getSelectedRows for further processing, you don't have to call if you don't need this.

</head>
<
body>
    <
script>

    var 
obj = new AW.UI.Grid;
    
obj.setCellData("cell");
    
obj.setHeaderText("header");
    
obj.setColumnCount(10);
    
obj.setRowCount(10);
    
obj.setCellEditable(true);
    
obj.setSelectorVisible(true);
    
obj.setSelectorWidth(25);
    
obj.setSelectorText(function(i){return this.getRowPosition(i)+1});
    
obj.setSelectionMode("multi-row");

    Array.
prototype.max = function()
        {return 
Math.max.apply({},this);}

    Array.
prototype.min = function()
        {return 
Math.min.apply({},this);}
    
    
//Remove duplicate values and sort asc
    
function RemoveDuplicateValues(array)
    {
        var 
i,j,resultArray=[];
        for (
= array.min(); i<=array.max();++i)
        {
            for (
j=0;j<=array.length;++j)
            {
                if (array[
j]==i)
                {
                    
resultArray.push(i);
                    break;
                }
            }
        }
        return 
resultArray;
    }

    var 
lastIndex;
    
obj.onRowMouseDown = function(eventindex)
    {
        if ((
event.shiftKey && event.ctrlKey) || event.shiftKey)
        {
            var 
rowmin Math.min(lastIndex,index);
            var 
rowmax Math.max(lastIndex,index);
            var 
selrows=[];
            for(
i=rowmini<=rowmax; ++i)
                {
selrows.push(i);}
            if (
event.ctrlKey//&&event.shiftKey
                
{obj.setSelectedRows(RemoveDuplicateValues(obj.getSelectedRows().concat(selrows)));}
            else 
//event.shiftKey
                
{obj.setSelectedRows(selrows);}
        }
        
lastIndex index;
    };
    
document.write(obj);

    </
script>
<
br>
<
button value="getSelectedRows" onClick="alert(obj.getSelectedRows());">get Selected Rows</button>
</
body>
</
html>
 
heis
Thursday, June 29, 2006
thanks for this improvement,

maybe it's better to change the key-events:

if (event.ctrlKey//&&event.shiftKey
                
{obj.setSelectedRows(selrows);}
            else 
//event.shiftKey
                
{obj.setSelectedRows(RemoveDuplicateValues(obj.getSelectedRows().concat(selrows)));}
 
kind regards
mono
Thursday, June 29, 2006
yeah it is good. However, it seems there is a problem after the sorting column event. Can you please try?
flashsnake
Friday, July 28, 2006



This topic is archived.

Back to /grid.doc.layout/

Documentation:

Forum search