Please help me!!! XML filter refresh??
My code is not sure working. He creates a Grid correctly in the first loading. But when I click button OK, which show the result of QUERY FILTER.
For example, I writed a text inside input, "CA". In case, he return two records.
Now! How do show (only these two records) in Grid using new AW.HTTP.Request calling file .php???
I only arrive get two records in first line, and each column is equivalent a record. It's wrong!!!
<html>
<head>
<title>ActiveWidgets Grid :: Examples</title>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;} </style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../../../runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="../../../runtime/lib/aw.js"></script>
<script src="fnc.js"></script>
<style>
.aw-system-control {position: absolute}
.aw-grid-control {height: 170px; width: 627px; border: none; font: menu; left: 50px; top: 50px;}
.aw-column-0 {width: 80px;}
.aw-column-1 {width: 200px; background-color: threedlightshadow;}
.aw-column-2 {text-align: right;}
.aw-column-3 {text-align: right;}
.aw-column-4 {text-align: right;}
.aw-grid-cell {border-right: 1px solid threedshadow;}
.aw-grid-row {border-bottom: 1px solid threedlightshadow;}
.aw-alternate-even {background: #eeeeee;}
#input1 {left: 135px; top: 20px; width: 230px; height: 20px;}
#btn0 {left: 370px; top: 18px; }
#btn1 {left: 112px; top: 300px; width: 82px;}
#btn2 {left: 200px; top: 300px; width: 82px;}
</style>
</head>
<!----------------------------------------------------------------------------->
<body>
<?
$conn = pg_connect("host=127.0.0.1 port=5432 dbname=certidoes_prontas user=postgres password=postgres")
or die("Erro na conexão com a base de dados");
$sql = pg_query("SELECT * FROM empresa ".(isset($_GET["pFilter"])?"WHERE cod = '".$_GET["pFilter"]."'":"")." ORDER BY cod");
$row = pg_num_rows($sql);
if($row)
{
$xml = "<xml version=\"1.0\" encoding=\"ISO-8859-1\" id=\"xmlDataIsland\">\n";
$xml .= "<companies>\n";
for($i=0; $i<$row; $i++)
{
$xml .= "<company>\n";
$xml .= "<ticker>".pg_result($sql, $i, "cod")."</ticker>\n";
$xml .= "<name>".pg_result($sql, $i, "dsc")."</name>\n";
$xml .= "<mktcap>".pg_result($sql, $i, "renda")."</mktcap>\n";
$xml .= "<sales>".pg_result($sql, $i, "salarios")."</sales>\n";
$xml .= "<employees>".pg_result($sql, $i, "empregados")."</employees>\n";
$xml .= "</company>\n";
}
$xml.= "</companies>\n";
$xml.= "</xml>";
if (isset($_GET["pXml"]))
{ Header("Content-type: application/xml; charset=iso-8859-1");
}
}
echo $xml;
?>
<script>
table = new AW.XML.Table;
table.setXML(document.getElementById("xmlDataIsland"));
// CRIACAO DO OBJETO GRID =====================================================
obj = new AW.UI.Grid;
var columns = ["Ticker", "Company Name", "Market Cap.", "$ Sales", "Employees"];
obj.setHeaderText(columns); //colunas do cabecalho
obj.setColumnCount(5); //numero de colunas
var numRow = document.getElementById("xmlDataIsland").getElementsByTagName("company").length;
obj.setRowCount(numRow);
// TIPOS DE FORMATOS ==========================================================
var str = new AW.Formats.String;
var num = new AW.Formats.Number;
obj.setCellFormat([str, str, num, num, num]);
// COLUNA LEGENDA =============================================================
obj.setSelectorVisible(true); //habilita a coluna legenda
obj.setSelectorText(function(i){return this.getRowPosition(i)+1}); //coloca na coluna legenda o numero de linhas obtidas
obj.setSelectorWidth(25); //largura da coluna legenda
// RODAPE =====================================================================
//obj.setFooterVisible(true); //habilita a coluna legenda
//obj.setBottomText("abc"); //texto da coluna legenda do rodape
// MODO DE SELECAO ============================================================
obj.setSelectionMode("single-row"); //habilita o modo de exibicao "toda as colunas de uma unica linha fica selecionado"
// obj.onCurrentRowChanged = function(c,r){alert(this.getCurrentProperty('selection'))}; //retorna o nome propriedade selecionada; 'column', 'row'
// PREENCHIMENTO DOS DADOS DO OBJETO LEITOR CSV
obj.setCellModel(table);
//===================================================================================
</script>
<div id="A" class="teste" style="display: ''">
<script>
var input = new AW.UI.Input;
input.setId("input1");
input.setControlText("");
input.setControlImage("search");
document.write(input);
var btn0 = new AW.UI.Button;
btn0.setId("btn0");
btn0.setControlText("OK");
btn0.onClick= function()
{
var r = new AW.HTTP.Request;
r.setURL("empresa.php");
r.setRequestMethod("GET");
r.setParameter("pFilter", input.getControlText());
r.setParameter("pXml", input.getControlText());
r.request();
r.response = function(data)
{
var numRow = this.getResponseXML().getElementsByTagName("company").length;
table.setXML(data);
obj.setRowCount(numRow);
obj.setCellModel(table);
obj.refresh();
}
}
document.write(btn0);
document.write(obj);
</script>
</div>
<script>
//Colocando o valor edit
obj.onKeyEnter = function(event)
{ input.setControlText(obj.getCellValue(0,obj.getCurrentRow()));
}
var btn1 = new AW.UI.Button;
btn1.setId("btn1");
btn1.setControlText("Mostrar");
btn1.onClick = function()
{ document.getElementById('A').style.display = '';
}
document.write(btn1);
//=========================================
var btn2 = new AW.UI.Button;
btn2.setId("btn2");
btn2.setControlText("Desaparecer");
btn2.onClick = function(){
document.getElementById('A').style.display = 'none';
}
document.write(btn2);
</script>
</body>
</html>
For example, I writed a text inside input, "CA". In case, he return two records.
Now! How do show (only these two records) in Grid using new AW.HTTP.Request calling file .php???
I only arrive get two records in first line, and each column is equivalent a record. It's wrong!!!
<html>
<head>
<title>ActiveWidgets Grid :: Examples</title>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;} </style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../../../runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="../../../runtime/lib/aw.js"></script>
<script src="fnc.js"></script>
<style>
.aw-system-control {position: absolute}
.aw-grid-control {height: 170px; width: 627px; border: none; font: menu; left: 50px; top: 50px;}
.aw-column-0 {width: 80px;}
.aw-column-1 {width: 200px; background-color: threedlightshadow;}
.aw-column-2 {text-align: right;}
.aw-column-3 {text-align: right;}
.aw-column-4 {text-align: right;}
.aw-grid-cell {border-right: 1px solid threedshadow;}
.aw-grid-row {border-bottom: 1px solid threedlightshadow;}
.aw-alternate-even {background: #eeeeee;}
#input1 {left: 135px; top: 20px; width: 230px; height: 20px;}
#btn0 {left: 370px; top: 18px; }
#btn1 {left: 112px; top: 300px; width: 82px;}
#btn2 {left: 200px; top: 300px; width: 82px;}
</style>
</head>
<!----------------------------------------------------------------------------->
<body>
<?
$conn = pg_connect("host=127.0.0.1 port=5432 dbname=certidoes_prontas user=postgres password=postgres")
or die("Erro na conexão com a base de dados");
$sql = pg_query("SELECT * FROM empresa ".(isset($_GET["pFilter"])?"WHERE cod = '".$_GET["pFilter"]."'":"")." ORDER BY cod");
$row = pg_num_rows($sql);
if($row)
{
$xml = "<xml version=\"1.0\" encoding=\"ISO-8859-1\" id=\"xmlDataIsland\">\n";
$xml .= "<companies>\n";
for($i=0; $i<$row; $i++)
{
$xml .= "<company>\n";
$xml .= "<ticker>".pg_result($sql, $i, "cod")."</ticker>\n";
$xml .= "<name>".pg_result($sql, $i, "dsc")."</name>\n";
$xml .= "<mktcap>".pg_result($sql, $i, "renda")."</mktcap>\n";
$xml .= "<sales>".pg_result($sql, $i, "salarios")."</sales>\n";
$xml .= "<employees>".pg_result($sql, $i, "empregados")."</employees>\n";
$xml .= "</company>\n";
}
$xml.= "</companies>\n";
$xml.= "</xml>";
if (isset($_GET["pXml"]))
{ Header("Content-type: application/xml; charset=iso-8859-1");
}
}
echo $xml;
?>
<script>
table = new AW.XML.Table;
table.setXML(document.getElementById("xmlDataIsland"));
// CRIACAO DO OBJETO GRID =====================================================
obj = new AW.UI.Grid;
var columns = ["Ticker", "Company Name", "Market Cap.", "$ Sales", "Employees"];
obj.setHeaderText(columns); //colunas do cabecalho
obj.setColumnCount(5); //numero de colunas
var numRow = document.getElementById("xmlDataIsland").getElementsByTagName("company").length;
obj.setRowCount(numRow);
// TIPOS DE FORMATOS ==========================================================
var str = new AW.Formats.String;
var num = new AW.Formats.Number;
obj.setCellFormat([str, str, num, num, num]);
// COLUNA LEGENDA =============================================================
obj.setSelectorVisible(true); //habilita a coluna legenda
obj.setSelectorText(function(i){return this.getRowPosition(i)+1}); //coloca na coluna legenda o numero de linhas obtidas
obj.setSelectorWidth(25); //largura da coluna legenda
// RODAPE =====================================================================
//obj.setFooterVisible(true); //habilita a coluna legenda
//obj.setBottomText("abc"); //texto da coluna legenda do rodape
// MODO DE SELECAO ============================================================
obj.setSelectionMode("single-row"); //habilita o modo de exibicao "toda as colunas de uma unica linha fica selecionado"
// obj.onCurrentRowChanged = function(c,r){alert(this.getCurrentProperty('selection'))}; //retorna o nome propriedade selecionada; 'column', 'row'
// PREENCHIMENTO DOS DADOS DO OBJETO LEITOR CSV
obj.setCellModel(table);
//===================================================================================
</script>
<div id="A" class="teste" style="display: ''">
<script>
var input = new AW.UI.Input;
input.setId("input1");
input.setControlText("");
input.setControlImage("search");
document.write(input);
var btn0 = new AW.UI.Button;
btn0.setId("btn0");
btn0.setControlText("OK");
btn0.onClick= function()
{
var r = new AW.HTTP.Request;
r.setURL("empresa.php");
r.setRequestMethod("GET");
r.setParameter("pFilter", input.getControlText());
r.setParameter("pXml", input.getControlText());
r.request();
r.response = function(data)
{
var numRow = this.getResponseXML().getElementsByTagName("company").length;
table.setXML(data);
obj.setRowCount(numRow);
obj.setCellModel(table);
obj.refresh();
}
}
document.write(btn0);
document.write(obj);
</script>
</div>
<script>
//Colocando o valor edit
obj.onKeyEnter = function(event)
{ input.setControlText(obj.getCellValue(0,obj.getCurrentRow()));
}
var btn1 = new AW.UI.Button;
btn1.setId("btn1");
btn1.setControlText("Mostrar");
btn1.onClick = function()
{ document.getElementById('A').style.display = '';
}
document.write(btn1);
//=========================================
var btn2 = new AW.UI.Button;
btn2.setId("btn2");
btn2.setControlText("Desaparecer");
btn2.onClick = function(){
document.getElementById('A').style.display = 'none';
}
document.write(btn2);
</script>
</body>
</html>
Anderson RS, Brazil.
August 8,