:: Forum >>

An Active.Xml.Table related issue

Hi,

How do i search a grid populated with XML Data. I am using the following code :

//Global
var table = new Active.XML.Table;

function searchGrid()
{
var colToBeSearched = document.getElementById('colSearchName').value;
var toSearch = document.getElementById('txtAdvSearch').value;
var res = 0;
//alert(obj.getDataModel());
for(var x=0; x<table.length; x++)
{
if((table[x][colToBeSearched].indexOf(toSearch)) >= 0)
{
obj.getTemplate("row", x).setStyle("color", "white");
obj.getTemplate("row", x).setStyle("background", "blue");
res++;
}
else
{
obj.getTemplate("row", x).setStyle("color", "black");
obj.getTemplate("row", x).setStyle("background", "white");
}
}
document.getElementById('result').innerHTML = "<b>Number of matches : "+res+"</b>";
}

Where am I wrong.

Cris Nagle
Wednesday, October 19, 2005
I never try it with xml, but seems to me that you need to play with "Nodes" because "table" is not a normal values array.
I would suggest search the forum topics for Node/Nodes.
Thanks
Carlos
Wednesday, October 19, 2005
Another way could be to convert xml to array with table.getText(i,j) and then search as above.
Check also this post:
http://activewidgets.com/javascript.forum.1079.2/get-xml-data-for-make.html
Carlos
Wednesday, October 19, 2005
Hi ,

Thanks for the example. In the code what does getXPathOfColumnToSearch(); contain and what is activeTableXML?

Could anyone provide a description on this.

Thanks
Cris Nagle
Wednesday, October 19, 2005
Hi carlos,

How do I use table.getText(i,j). That is how do i get i and j. Once the xml is converted to array, how do i convert it back to XML and bind it to the Grid.

I hope you can help me out.
Thanks.
Cris Nagle
Wednesday, October 19, 2005
I usually do it with csv-table (not sure, but xml should be similar),
for csv-getText(i,j) check the links inside this post:
http://activewidgets.com/javascript.forum.6777.1/using-aw-as-a-query.html
Thanks
Carlos
Wednesday, October 19, 2005
Hey Carlos,

Thanks man. I tried it on my own and was able to search the rows.

Thanks.
Cris Nagle
Wednesday, October 19, 2005
Hi Carlos,

Using this code, I am able to get the rows that match the text :

var colToBeSearched = document.getElementById('colSearchName').options[document.getElementById('colSearchName').selectedIndex].text;
var stringToFind = document.getElementById('txtAdvSearch').value;
var xmlDoc = table.getXML();
var nodes = xmlDoc.selectNodes("//doc/docs/" + colToBeSearched);
var matchingRows = new Array();
for(i=0;i<nodes.length;i++)
{
var s = nodes[i].text

if (s.match(stringToFind))
{
matchingRows.push( i );
}
}
alert(matchingRows);

The matching rows contains the rows that contains the matches.
My question is how do I bind these matching rows to the grid so that the grid shows only the matched rows.

Sorry I am just not familiar with java script.

Thanks for the help.
Cris Nagle
Wednesday, October 19, 2005

This topic is archived.


Back to support forum

Forum search