3.2.0

kind of footer implementation (paging issue)

I was looking for the solution to implement footer in AW version 1. Finally, I decided to implement it in the next way:
1) initially footer is the last row in the data array
2) copy last row (footer) into new array
2) on sort remove last row and sort the data
3) add new row (copy from footer array)
4) refresh grid

An example you can find bellow:
<html>
<head>
    <link href="../../runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
    <script src="../../runtime/lib/grid.js"></script>
    <script src="../../patches/paging1.js"></script>
    <style>
        .active-controls-grid {height: 100%; border: 1px solid #ccc; font: menu;}
    </style>

    <script>
  var myColumns = [
"Date","MAILFROM","RCPTTO","REJECTED","COUNT","SIZE"
];

var myData = [
["2006-06-01", "agpkvgymznezqo@pochta.ru", "info@domain.com", "blacklisted", "1", "0"],
["2006-06-01", "prdvtatajyao@qni.com", "info@domain.com", "read-error", "1", "0,03"],
["2006-06-01", "wwdvcfi@bgta.com", "asm@domain.com", "spam", "1", "0,01"],
["2006-06-01", "artf6ofqn7@mail.ru", "asm@domain.com", "spam", "1", "0,01"],
["2006-06-01", "talt@geta.com", "asm@domain.com", "spam", "1", "0,01"],
["2006-06-01", "chopino@entermediate.com", "asm@domain.com", "spam", "1", "0,01"],
["2006-06-01", "watson@airpower-ent.com", "asm@domain.com", "spam", "1", "0,01"],
["2006-06-01", "gmitchell@ae.com", "asm@domain.com", "spam", "1", "0,01"],
["2006-06-01", "Carolynjimzros@brainydictionary.com", "asm@domain.com", "spam", "1", "0"],
["2006-06-01", "Judithabqhwxjw@takebackthemedia.com", "asm@domain.com", "spam", "1", "0"],
["2006-06-01", "club79191296.1149116404@club.mnogo.ru", "asm@domain.com", "spam", "1", "0"],
["2006-06-01", "iyjxkmeqehp@hotmail.com", "asm@domain.com", "spam", "1", "0"],
["2006-06-01", "iny@bspa.com", "info@domain.com", "spam", "1", "0,05"],
["2006-06-01", "ujfqgeurztx@hopa.com", "info@domain.com", "spam", "1", "0,05"],
["2006-06-01", "hpsnolvxosa@misa.com", "info@domain.com", "spam", "1", "0,05"],
["2006-06-01", "tyaayp@ipla.com", "info@domain.com", "spam", "1", "0,05"],
["2006-06-01", "lztvf@pksa.com", "info@domain.com", "spam", "1", "0,04"],
["2006-06-01", "nzgmaf@pmh.com", "info@domain.com", "spam", "1", "0,04"],
["2006-06-01", "epnexj@zzra.com", "info@domain.com", "spam", "1", "0,04"],
["2006-06-01", "alkama@mail.ru", "info@domain.com", "spam", "1", "0,04"],
["2006-06-01", "twkf@upi.com", "info@domain.com", "spam", "1", "0,04"],
["2006-06-01", "shhqftr@gci.com", "info@domain.com", "spam", "1", "0,04"],
["2006-06-01", "ghost@kis.ru", "info@domain.com", "spam", "1", "0,04"],
["2006-06-01", "rzfjitg@cbra.com", "info@domain.com", "spam", "1", "0,04"],
["2006-06-01", "hvhn@brh.com", "info@domain.com", "spam", "1", "0,03"],
["-", "-", "-", "-", "25", "0,64"]
];

  var myFooter = [];
  for (i=0;i<myColumns.length;i++) myFooter[i] = myData[myData.length-1][i];
  
    </script>
</head>
<body>

    <hr>
    <div>
        <button onclick='goToPage(-Infinity)'>&lt;&lt;</button>
        <button onclick='goToPage(-1)'>&lt;</button>
        <span id='pageLabel'></span>
        <button onclick='goToPage(1)'>&gt;</button>
        <button  onclick='goToPage(Infinity)'>&gt;&gt;</button>
        <button onclick="SortWithFooter(5,'descending')">Sort by size (D)</button>
        <button onclick="SortWithFooter(5,'ascending')">Sort by size (A)</button>
    </div>
    <hr>

<script>
    var obj = new Active.Controls.Grid;

    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    Without paging everything works fine (just comment the line below)
    // obj.setModel("row", new Active.Rows.Page);

    
    obj.setRowProperty("count", myData.length);
    obj.setColumnProperty("count", myColumns.length);
        
    obj.setDataProperty("text", function(i, j){return myData[i][j]});
    obj.setColumnProperty("text", function(i){return myColumns[i]});

    obj.getTemplate("top/item").setEvent("onmousedown", null); 

    
    document.write(obj);
    

</script>
    
<script>

function goToPage(delta){
        var count = obj.getProperty("row/pageCount");
        var number = obj.getProperty("row/pageNumber");
        number += delta;
        if (number < 0) {number = 0}
        if (number > count-1) {number = count-1}
        document.getElementById('pageLabel').innerHTML = "Page " + (number + 1) + " of " + count + " ";

        obj.setProperty("row/pageNumber", number);
        obj.refresh();
}	

    goToPage(0);	


function SortWithFooter(idx, direction) { 
    var index = obj.getProperty("selection/index");
    deleteRow(false);
    obj.sort(idx,direction);
    addRow(myFooter, false);
    obj.setProperty("selection/index",index);
    obj.refresh();
};
    
function addRow(row, refresh){
    var index_values = obj.getRowProperty("values");
    // add new row
    myData.push(row);
    // update grid row indices
    index_values.push(myData.length - 1);
    obj.setRowProperty("values", index_values);
    obj.setRowProperty("count", myData.length);
    if (refresh) {this.obj.refresh();} 		
};
    
function deleteRow(refresh){
    // Get existing sort values, re-number then deleted element
    var array = obj.getRowProperty("values");
    index = array.length-1;
    var splice_point=-2;
    var new_selected_row=-1;
 
    for (var i=0;i<array.length;i++){
         if (array[i] == index) splice_point=i;

         if (array[i] > index) array[i]--;

         if (splice_point == i-1) new_selected_row=array[i];
    }

    // Check the values are ok just to be sure
    if (splice_point >= 0) array.splice(splice_point,1);
    if (new_selected_row == -1) new_selected_row=array[array.length-1];

     myData.splice(index,1);
    
     // re-initialize the data values
     this.obj.setDataProperty("count", myData.length);

    // Put back the sort values
    this.obj.setRowProperty("values", array);
    //        obj.setProperty("selection/index",new_selected_row);
    this.obj.setProperty("selection/index",new_selected_row);

    // refresh the grid
    if(refresh) {obj.refresh();}	
};
</script>
</body>
</html>


It works good enough, but only without paging patch. As soon as I add paging functionality, the code doesn't work any more. I spent 3 days and haven't found any solutions. I guess this issue is due to the "reload/change data after sort" bug but I don't think I have any ideas how to fix it.

Any help/suggestions will be very much appreciated.

Thanks in advance
Andrew M.
August 16,

This topic is archived.

See also:


Back to support forum