Problem with SORT method in Version 1.0
Hi, in reference at http://www.activewidgets.com/javascript.forum.1394.55/textbox-template-edit-on-double.html
I have a problem with after edit a value of cell i execute the Sort method, this method replace all values of my grid by the last value modified.
Example:
1. Data of my Grid
col1 col2 col3 .... colN
1 2 3 N
4 5 6 N
2. DoubleClick for cell (row 1, col 1) and put the value 7.
3. Push in the header of column 2 and execute sort method, this method
replace all values by 7
col1 col2 col3 .... colN
7 7 7 7
7 7 7 7
some help, please !!!
my Code:
<html><head>
<link href="/js/grid/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="/js/grid/grid.js"></script>
<!-- grid format -->
<style>
body, html {margin:0px; padding: 0px; overflow: hidden; border: none;}
.active-controls-grid {height: 100%; font: menu;}
.active-column-0 {text-align:left;width:200px;}
.active-column-1 {width:200px; }
.active-column-2 {width:60px;}
.active-column-3 {text-align: right;width: 50px;}
.active-column-4 {width:60px;}
.active-column-5 {width:60px;}
.active-grid-column {border-right: 1px solid threedlightshadow;}
.active-grid-row {border-bottom: 1px solid threedlightshadow;}
.active-grid-row {
height: 18px;
background: #fff;
}
.active-templates-row.gecko {
display: -moz-box;
width: auto;
min-width: 100%;
}
.active-edit-mode {
overflow: auto;
padding: 0px;
vertical-align: top;
}
.active-templates-input {
overflow: hidden;
width: 100%;
height: 100%;
padding: 0px 5px;
margin: -1px 0px;
border: 1px solid #3581FF;
vertical-align: middle;
font: menu;
line-height: 1.4em;
}
.active-templates-input.gecko {
display: block;
margin: 0px;
}
.active-row-highlight {background-color: #ddeeff!important}
.active-row-highlight .active-row-cell {background-color: #ddeeff;}
.active-box-input {border: none;font: menu;background-color: #ff0000;}
.barra {
scrollbar-3dlight-color: #999999;
scrollbar-arrow-color: #999999;
scrollbar-base-color: #F0F0F0;
scrollbar-darkshadow-color: #F0F0F0;
scrollbar-face-color: #F0F0F0;
scrollbar-highlight-color: #F0F0F0;
scrollbar-shadow-color: #999999;
}
</style>
<script>
var myData = [[...]];
var myValues = [[...]];
var myColumns = [[...]];
</script>
</head>
<body class="barra" oncontextmenu="return true;">
<script>
// MONTAMOS EL INPUT
// ###################################
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
My.Templates.Currency = Active.Templates.Text.subclass();
My.Templates.Currency.create = function()
{
var obj2 = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new Active.HTML.INPUT;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
//En el atributo name nos guardamos el codigo de cuenta.
editor.setAttribute("name", function(){
return template2.getItemProperty("value");
});
editor.setAttribute("value", function(){
return template2.getItemProperty("text");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template2;
function switchToEditMode(){
if (template2) {
switchToTextMode();
}
// Celdas undefined no editables
if (this.element().innerHTML == "undefined") return;
template2 = this;
template.element().className += "active-edit-mode";
//template2.element().style.padding = 0;
//Actualizamos los nuevos valores del editor.
editor.setAttribute("value",template2.element().innerHTML);
editor.setAttribute("name",template2.getItemProperty("value"));
template2.element().innerHTML = editor;
editor.element().focus();
}
obj2.setEvent("ondblclick", this.focus);
obj2.setEvent("ondblclick", switchToEditMode);
function switchToTextMode(){
var originalVal = template2.getItemProperty("text");
var value = editor.element().value;
var vError = 0;
// Controlamos que en el código postal solo se introduzcan números.
if (template2.getColumnProperty("index") == 3){
try {
if(isNaN(value)) {
alert("Solo se pueden introducir números.");
vError = 1;
}
// Por si queremos poner mascara.
//var format = new Active.Formats.Number;
//format.setTextFormat("#,###.##");
//value = format.dataToText(value);
}
catch(error){
//ignore errors
}
}
// Comprobamos si ha cambiado el valor.
if(originalVal != value && vError == 0){
// value changed, call the callback function
var row = template2.getRowProperty("index");
var col = template2.getColumnProperty("index");
// Insertamos el nuevo valor
alert(template2.element().innerHTML);// = value;
//template2.setDataProperty("text", value);
template2.setDataProperty("text", value, row);
//Actualizamos
//updateData(editor.element().name,col,value);
}
template2.refresh();
template2 = null;
}
editor.setEvent("onblur", switchToTextMode);
};
My.Templates.Currency.create();
// ##############################################
// ##############################################
// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
// Ponemos el rollover de la fila
var alternate = function(){
return this.getProperty("row/order") % 2 ? "#fcfaf6" : "#ffffff";
}
var row = new Active.Templates.Row;
row.setStyle("background", alternate);
row.setEvent("onmouseover", "mouseover(this, ''active-row-highlight'')");
row.setEvent("onmouseout", "mouseout(this, ''active-row-highlight'')");
obj.setTemplate("row", row);
// Creamos la plantilla para poner el campo editable (input).
// ######################################################
var template = new My.Templates.Currency;
// Asignamos el campo editable al grid
obj.setColumnTemplate(template);
// Con esto evitamos que cuando estamos dentro del input si pulsamos
// alguna flecha no se salga de éste.
obj.setEvent("onkeydown", null);
obj.getTemplate("top").setEvent("onselectstart", obj.getEvent("onselectstart"));
obj.setEvent("onselectstart", null);
// ######################################################
// Rellenamos los datos del GRID.
obj.setDataProperty("text", function(i, j){return myData[i][j]});
obj.setDataProperty("value", function(i, j){return myValues[i][j]});
obj.setColumnProperty("text", function(i){return myColumns[i]});
// Nº de filas y Nº de columnas del GRID. Las columnas empiezan por 0.
obj.setRowProperty("count", "6");
obj.setColumnProperty("count", "");
// write grid html to the page
document.write(obj);
</script>
</body>
</html>
I have a problem with after edit a value of cell i execute the Sort method, this method replace all values of my grid by the last value modified.
Example:
1. Data of my Grid
col1 col2 col3 .... colN
1 2 3 N
4 5 6 N
2. DoubleClick for cell (row 1, col 1) and put the value 7.
3. Push in the header of column 2 and execute sort method, this method
replace all values by 7
col1 col2 col3 .... colN
7 7 7 7
7 7 7 7
some help, please !!!
my Code:
<html><head>
<link href="/js/grid/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="/js/grid/grid.js"></script>
<!-- grid format -->
<style>
body, html {margin:0px; padding: 0px; overflow: hidden; border: none;}
.active-controls-grid {height: 100%; font: menu;}
.active-column-0 {text-align:left;width:200px;}
.active-column-1 {width:200px; }
.active-column-2 {width:60px;}
.active-column-3 {text-align: right;width: 50px;}
.active-column-4 {width:60px;}
.active-column-5 {width:60px;}
.active-grid-column {border-right: 1px solid threedlightshadow;}
.active-grid-row {border-bottom: 1px solid threedlightshadow;}
.active-grid-row {
height: 18px;
background: #fff;
}
.active-templates-row.gecko {
display: -moz-box;
width: auto;
min-width: 100%;
}
.active-edit-mode {
overflow: auto;
padding: 0px;
vertical-align: top;
}
.active-templates-input {
overflow: hidden;
width: 100%;
height: 100%;
padding: 0px 5px;
margin: -1px 0px;
border: 1px solid #3581FF;
vertical-align: middle;
font: menu;
line-height: 1.4em;
}
.active-templates-input.gecko {
display: block;
margin: 0px;
}
.active-row-highlight {background-color: #ddeeff!important}
.active-row-highlight .active-row-cell {background-color: #ddeeff;}
.active-box-input {border: none;font: menu;background-color: #ff0000;}
.barra {
scrollbar-3dlight-color: #999999;
scrollbar-arrow-color: #999999;
scrollbar-base-color: #F0F0F0;
scrollbar-darkshadow-color: #F0F0F0;
scrollbar-face-color: #F0F0F0;
scrollbar-highlight-color: #F0F0F0;
scrollbar-shadow-color: #999999;
}
</style>
<script>
var myData = [[...]];
var myValues = [[...]];
var myColumns = [[...]];
</script>
</head>
<body class="barra" oncontextmenu="return true;">
<script>
// MONTAMOS EL INPUT
// ###################################
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
My.Templates.Currency = Active.Templates.Text.subclass();
My.Templates.Currency.create = function()
{
var obj2 = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new Active.HTML.INPUT;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
//En el atributo name nos guardamos el codigo de cuenta.
editor.setAttribute("name", function(){
return template2.getItemProperty("value");
});
editor.setAttribute("value", function(){
return template2.getItemProperty("text");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template2;
function switchToEditMode(){
if (template2) {
switchToTextMode();
}
// Celdas undefined no editables
if (this.element().innerHTML == "undefined") return;
template2 = this;
template.element().className += "active-edit-mode";
//template2.element().style.padding = 0;
//Actualizamos los nuevos valores del editor.
editor.setAttribute("value",template2.element().innerHTML);
editor.setAttribute("name",template2.getItemProperty("value"));
template2.element().innerHTML = editor;
editor.element().focus();
}
obj2.setEvent("ondblclick", this.focus);
obj2.setEvent("ondblclick", switchToEditMode);
function switchToTextMode(){
var originalVal = template2.getItemProperty("text");
var value = editor.element().value;
var vError = 0;
// Controlamos que en el código postal solo se introduzcan números.
if (template2.getColumnProperty("index") == 3){
try {
if(isNaN(value)) {
alert("Solo se pueden introducir números.");
vError = 1;
}
// Por si queremos poner mascara.
//var format = new Active.Formats.Number;
//format.setTextFormat("#,###.##");
//value = format.dataToText(value);
}
catch(error){
//ignore errors
}
}
// Comprobamos si ha cambiado el valor.
if(originalVal != value && vError == 0){
// value changed, call the callback function
var row = template2.getRowProperty("index");
var col = template2.getColumnProperty("index");
// Insertamos el nuevo valor
alert(template2.element().innerHTML);// = value;
//template2.setDataProperty("text", value);
template2.setDataProperty("text", value, row);
//Actualizamos
//updateData(editor.element().name,col,value);
}
template2.refresh();
template2 = null;
}
editor.setEvent("onblur", switchToTextMode);
};
My.Templates.Currency.create();
// ##############################################
// ##############################################
// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
// Ponemos el rollover de la fila
var alternate = function(){
return this.getProperty("row/order") % 2 ? "#fcfaf6" : "#ffffff";
}
var row = new Active.Templates.Row;
row.setStyle("background", alternate);
row.setEvent("onmouseover", "mouseover(this, ''active-row-highlight'')");
row.setEvent("onmouseout", "mouseout(this, ''active-row-highlight'')");
obj.setTemplate("row", row);
// Creamos la plantilla para poner el campo editable (input).
// ######################################################
var template = new My.Templates.Currency;
// Asignamos el campo editable al grid
obj.setColumnTemplate(template);
// Con esto evitamos que cuando estamos dentro del input si pulsamos
// alguna flecha no se salga de éste.
obj.setEvent("onkeydown", null);
obj.getTemplate("top").setEvent("onselectstart", obj.getEvent("onselectstart"));
obj.setEvent("onselectstart", null);
// ######################################################
// Rellenamos los datos del GRID.
obj.setDataProperty("text", function(i, j){return myData[i][j]});
obj.setDataProperty("value", function(i, j){return myValues[i][j]});
obj.setColumnProperty("text", function(i){return myColumns[i]});
// Nº de filas y Nº de columnas del GRID. Las columnas empiezan por 0.
obj.setRowProperty("count", "6");
obj.setColumnProperty("count", "");
// write grid html to the page
document.write(obj);
</script>
</body>
</html>
APerez
November 5,