var obj = new Active.Controls.Grid;
// count the number of header rows as defined in a .jsp result set
<% lm.rs.last(); %>
obj.setRowCount(<%=lm.rs.getRow()%>);
obj.setColumnCount(<%=lm.listColumns.size()%>);
obj.setDataText(function(i, j){return myData[i][j]});
obj.setColumnText(function(i){return myColumns[i]});
// dblclick setup
var row = obj.getTemplate("row");
row.setEvent("ondblclick", function(){this.action("dblClickAction")});
obj.setAction("dblClickAction", function(src){
var i = src.getProperty("item/index");
alert(this.getDataText(i,0) + ' ' + this.getItemProperty("text"));
});
document.write(obj);
public String getGridLibreriaMedidasProductosQuimicos (String nombreGrid, String nombreColumnas, String nombreArray, String nombreCheckBox)
{
String codigo = "";
int i = 0;
boolean primera_linea = true;
codigo = "var " + nombreArray + " = [";
try
{
BD bd = new BD();
String sql = "SELECT * FROM cod_medidas_producto ORDER BY descripcion";
ResultSet rs = bd.getConjuntoResultados(sql);
while(rs.next())
{
if(primera_linea) primera_linea = false;
codigo += "\n[\"<input type='checkbox' name='" + nombreCheckBox + "[]' value='" + i + "'> " + rs.getString("descripcion") + "\",\"" + rs.getString("id_cod_medidas") + "\",\"" + rs.getString("descripcion") + "\"],";
i++;
}
if(!primera_linea) codigo = codigo.substring(0,(codigo.length()-1));
codigo += "\n];\n";
codigo += "var " + nombreColumnas + " = [\"Medida\"];";
codigo += "\n" + nombreGrid + ".setRowCount(" + i+ ");";
codigo += "\n" + nombreGrid + ".setColumnCount(1);";
rs.close();
bd.close();
}
catch (Exception e)
{
System.out.println("@Presupuesto@getGridLibreriaMedidasProductosQuimicos: " + e.getMessage ());
}
return codigo;
}
<script>
var misDatos = new Array(200);
misDatos[0] = new Array(3);
misDatos[0][0] = "NAN";
misDatos[0][1] = "NAN";
misDatos[0][2] = "NAN";
var longitud = 0;
function insertarProducto()
{
valido = true;
var d=document.forms[0].elements['chkProductosEmpresa[]'];
var posMatriz = 0;
for(i=0;i<d.length;i++)
{
// El valor del checkbox se corresponde con la posición del array en su posicion [2] de forma que sirve como
// indice de la matriz
if(d[i].checked)
{
posMatriz = d[i].value;
misDatos[longitud] = new Array(3);
texto = "";
misDatos[longitud][0] = arrayProductosEmpresa[posMatriz][3];
misDatos[longitud][1] = arrayProductosEmpresa[posMatriz][1];
misDatos[longitud][2] = arrayProductosEmpresa[posMatriz][2];
longitud++;
}
}
for(i=0;i<longitud;i++)
{
texto += "<input type=\"hidden\" name=\"valores_producto\" value=\"" + misDatos[i][2] + "\">";
}
obj.setRowCount(longitud);
obj.refresh();
document.all["valores_ocultos"].innerHTML = texto;
}
SDI.Templates.Checkbox = Active.System.Template.subclass();
SDI.Templates.Checkbox.create = function(){
/****************************************************************
Checkbox Cell template.
*****************************************************************/
var obj = this.prototype;
var _super = this.superclass.prototype;
obj.setTag("div");
obj.setClass("templates","input");
obj.getName = function() {
return this.getCellName();
}
obj.getCellName = function() {
var r = this.getRowProperty("index");
var c = this.getColumnProperty("index");
if (!r) r = 0;
if (!c) c = 0;
return "grid_item_"+r+"_"+c;
}
obj._checkedStatus = false;
obj._checkedValue = "true";
obj.setCheckedValue = function( v ) { this._checkedValue = v; }
obj.getCheckedValue = function( ) { return this._checkedValue; }
obj._uncheckedValue = "";
obj.setUncheckedValue = function( v ) { this._uncheckedValue = v; }
obj.getUncheckedValue = function( ) { return this._uncheckedValue; }
obj.hidden = new Active.HTML.INPUT;
obj.hidden.setAttribute("type", "hidden");
obj.hidden.setAttribute("name", function(){ return this.getName(); });
obj.hidden.setAttribute("value", function(){
var v = this.isChecked() ? this.getCheckedValue() : this.getUncheckedValue();
return v;
});
obj.checkbox = new Active.HTML.INPUT;
obj.checkbox.setClass("input","checkbox");
obj.checkbox.setClass("checkbox",function(){return this.getColumnProperty("index");});
obj.checkbox.setAttribute("type","checkbox");
obj.checkbox.setAttribute("checked", function(){return this.isChecked() ? "true" : null;} );
obj.checkbox.setEvent("onclick", function( event, src ){
this.checkboxClicked( event, src );
});
obj.getCheckbox = function() {return checkbox;}
obj.label = new Active.HTML.SPAN;
obj.label.setClass("checkbox","label");
obj.label.setContent("text", function() { return this.getItemProperty("text"); });
obj.setLabel = function( text ) {
this.label.setContent( "text", text );
}
obj.checkboxClicked = function( event ) {
var b = event.srcElement.checked;
if (this._sdiGrid) {
var r = this.getRowProperty("index");
var c = this.getColumnProperty("index");
var node = this._xmlModel.getNode( r, c );
node.setAttribute( "change", b ? this.getCheckedValue() : this.getUncheckedValue() );
node.setAttribute( "ognl", this.getName() );
if (c && c.length>0) mv = c;
}
this.refresh();
}
obj.isChecked = function(){
var ipt = this.getItemProperty("text");
var mv = ModelUtils.getModelValue(this);
var cv = this.getCheckedValue();
var b = ( mv == cv );
if (this._xmlModel) {
var r = this.getRowProperty("index");
var c = this.getColumnProperty("index");
var node = this._xmlModel.getNode( r, c );
var change = node.getAttribute( "change" );
if (change && change.length>0) b = (change == cv);
}
return b;
}
obj.setContent("checkbox", obj.checkbox );
obj.setContent("label", obj.label);
obj.setContent("hidden", obj.hidden);
};
SDI.Templates.Checkbox.create();
var grid = ...
var cbTemplate = new SDI.Templates.Checkbox;
cbTemplate.setCheckedValue("Y");
cbTemplate.setUncheckValue("N");
grid.setColumnTemplate( cbTemplate, cbIndex );
This topic is archived.