M
mark4asp
How do I use push on to a 2-D array?
Here is my scenario: I have a 2-D array called aSort. aSort stores the
column number of a html table and the sort order for that column of
the table. (Sort order is 'A' or 'D', A for ascending and D for
descending. Column Number will be: '0', '1', '2', ...). aSort has a
maximum number of rows set by gridMaxSortCols. So the client clicks on
the table header to sort the data and aSort is to remember a stack of
such client clicks (which column was clicked and whether it was
ascending or descending). The size of the stack = gridMaxSortCols,
which is the maximum number of such column sorts to be remembered. In
the case of the same column sorted twice only the most recent sort is
to be remembered.
push is to work like this:
1. If an item is already in the stack it is removed.
2. If the size of the stack == gridMaxSortCols an item is popped.
3. The item is pushed on to the stack.
An item is a pair of values. e.g. if the client clicked the table to
sort the 3rd column (descending) then the item will be '2','D' and I
would call push('2','D').
How do I do this?
aSort.push(); // what do I do here to push '2','D'? where aSort is a 2-
D array.
var gridMaxSortCols = 2
var aSort = new Array(gridMaxSortCols,2);
function push(column,order) {
// If an item is already in the stack it is removed and the new one
added.
// copy all the items which are not this column to a temp array then
set aSort to the values of the temp array.
var aSortTemp = new Array(gridMaxSortCols,2);
for (var i = 0; i < aSort.length ; i++){
if (column != gridMaxSortCols[0]){
aSortTemp[0] = aSort[0];
aSortTemp[1] = aSort[1];
}
aSort = aSortTemp;
//If the size of the stack == gridMaxSortCols an item is popped and
the new one pushed.
if(aSort.length == gridMaxSortCols)
aSort.pop();
//otherwise the item is just pushed.
aSort.push('2','D'); // what do I do here to push '2','D' ?
}
}
PS: which versions of IE with push() and pop() work with?
Here is my scenario: I have a 2-D array called aSort. aSort stores the
column number of a html table and the sort order for that column of
the table. (Sort order is 'A' or 'D', A for ascending and D for
descending. Column Number will be: '0', '1', '2', ...). aSort has a
maximum number of rows set by gridMaxSortCols. So the client clicks on
the table header to sort the data and aSort is to remember a stack of
such client clicks (which column was clicked and whether it was
ascending or descending). The size of the stack = gridMaxSortCols,
which is the maximum number of such column sorts to be remembered. In
the case of the same column sorted twice only the most recent sort is
to be remembered.
push is to work like this:
1. If an item is already in the stack it is removed.
2. If the size of the stack == gridMaxSortCols an item is popped.
3. The item is pushed on to the stack.
An item is a pair of values. e.g. if the client clicked the table to
sort the 3rd column (descending) then the item will be '2','D' and I
would call push('2','D').
How do I do this?
aSort.push(); // what do I do here to push '2','D'? where aSort is a 2-
D array.
var gridMaxSortCols = 2
var aSort = new Array(gridMaxSortCols,2);
function push(column,order) {
// If an item is already in the stack it is removed and the new one
added.
// copy all the items which are not this column to a temp array then
set aSort to the values of the temp array.
var aSortTemp = new Array(gridMaxSortCols,2);
for (var i = 0; i < aSort.length ; i++){
if (column != gridMaxSortCols[0]){
aSortTemp[0] = aSort[0];
aSortTemp[1] = aSort[1];
}
aSort = aSortTemp;
//If the size of the stack == gridMaxSortCols an item is popped and
the new one pushed.
if(aSort.length == gridMaxSortCols)
aSort.pop();
//otherwise the item is just pushed.
aSort.push('2','D'); // what do I do here to push '2','D' ?
}
}
PS: which versions of IE with push() and pop() work with?