Hi,

I am trying to use multiple filters on a nested data set using Spry but it does not work, no matter how many times I've re-read the code and verified that I'm using the code the right way. What is going on?

When I use a single non-destructive filter (ie... ds.filter()) on the nested data set, the filter works beautifully. However, when I want to use multiple filters (I use ds.addFilter()), it looks like my filter function (FilterByState) is not being kicked off.

I linked to the appropriate files, SpryData.js, xpath.js, SpryNestedXMLDataSet.js and SpryDataExtensions.js. These are the latest version, 1.6.1.

Why will ds.filter work and not ds.addFilter? I haven't written the second filter code yet because this is stopping me from moving forward. Even though, I haven't written that, shouldn't addFilter work too?

Please help, this is driving me crazy.

Here is my code:

<script type="text/javascript">
Spry.Utils.addLoadListener(function () {
if (document.getElementById("stateSelect").selectedIndex != 0) {
document.getElementById("stateSelect").selectedIndex = 0;
}

if (document.getElementById("dateSelect").selectedIndex != 0) {
document.getElementById("dateSelect").selectedIndex = 0;
}
});
var dsTopics = new Spry.Data.XMLDataSet("compliance.xml", "compliance/subject", {useCache: false });
var dsDocuments = new Spry.Data.NestedXMLDataSet(dsTopics, "doc");
var dsDates = new Spry.Data.XMLDataSet("compliance.xml", "compliance/subject/doc/date", {useCache: false, subPaths: "@num", distinctOnLoad: true, distinctFieldsOnLoad: ['date'], sortOnLoad: "@num", sortOrderOnLoad:"ascending"});
dsDates.setColumnType("@num", "number");

var currentSelection;
//var FilterByState;

function showDocuments(currentIndex) {
dsTopics.setCurrentRowNumber(currentIndex);
document.getElementById("stateSelect").selectedIndex = 0;
document.getElementById("dateSelect").selectedIndex = 0;

dsDocuments.removeAllFilters(true);
}

function ToggleFilter(selected, f) {
chosenState = selected;

if (selected != "") {
alert("something's selected");
dsDocuments.addFilter(f, true);
}
else {
alert("something is NOT selected");
dsDocuments.removeFilter(f, true);
}
//dsDocuments.applyFilters();
}

var chosenState;
var chosenDate;

function FilterByState(ds, row, rowNumber) {
alert("Filtering by state");
var currentSelection = document.getElementById("stateSelect").options[chosenState];

if (row["state"].search(currentSelection.value) != -1) {
return row;
}

else
return null;
}

function FilterByDate(ds, row, rowNumber) {
var currentSelectedDate = document.getElementById("dateSelect").options[chosenDate];

if (row["date"] == currentSelectedDate)
return row;

else
return null;
}
</script>

<div class="articlePage articleContent">
<h2 class="bodyCopyBold">Compliance Widget</h2>
<form name="selectForm" action="">

<div spry:region="dsTopics" id="topicSelector">
<label for="topicSelect" class="dataLabel">Topic:</label>
<select spry:repeatchildren="dsTopics" class="input" name="topicSelect" id="topicSelect" onchange="showDocuments(this.selectedIndex);">
<option spry:if="{ds_RowNumber} == {ds_CurrentRowNumber}" value="{name}" selected="selected">{name}</option>
<option spry:if="{ds_RowNumber} != {ds_CurrentRowNumber}" value="{name}">{name}</option>
</select>
</div>

<label for="stateSelect" class="dataLabel">State:</label>
<select class="input" name="stateSelect" id="stateSelect" onchange="ToggleFilter(this.selectedIndex, FilterByState);">
<option value="" selected="selected">Please Select</option>
<option value="All States">All States</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>

<div spry:region="dsDates" id="dateSelector">
<label for="dateSelect" class="dataLabel">Date:</label>
<select class="input" name="dateSelect" id="dateSelect">
<option value="" selected="selected">Please Select</option>
<option spry:repeat="dsDates" value="{date}">{date}</option>
</select>
</div>

<div class="spacer10"></div>

<div id="documentListing" class="bodyCopy">
<ul spry:region="dsDocuments" spry:detailregion="dsTopics" class="list2">
<li spry:repeat="dsDocuments">{title}</li>
</ul>
</div>
</form>

Here is the xml

<?xml version="1.0"?>
<compliance>
<subject>
<name>Agent Termination</name>
<doc id="91000038">
<title>Reminder: Agent Contract Termination Notification</title>
<date num="200907">July 2009</date>
<state>OR</state>
</doc>
<doc id="91000031">
<title>Reminder: Agent Contract Termination Notification 2</title>
<date num="200807">July 2008</date>
<state>OR</state>
</doc>
<doc id="91000031">
<title>Reminder: Agent Contract Termination Notification 2</title>
<date num="201001">January 2010</date>
<state>OR</state>
</doc>
</subject>
<subject>
<name>Agent Training</name>
<doc id="91000034">
<title>Oregon Agent Retraining</title>
<date num="200908">August 2009</date>
<state>OR</state>
</doc>
<doc id="91000060">
<title>Multi-State Corrective Action Plan - Training Courses BLN Changes</title>
<date num="200902">February 2009</date>
<state>All States</state>
</doc>
<doc id="91000062">
<title>Required Training Change for California Agents</title>
<date num="200902">February 2009</date>
<state>CA</state>
</doc>
<doc id="91000065">
<title>Required Training - BCLIC Agents</title>
<date num="200902">February 2009</date>
<state>NY</state>
</doc>
<doc id="91000071">
<title>Multi-State Corrective Action Plan - Training Courses BLN Changes</title>
<date num="200901">January 2009</date>
<state>All States</state>
</doc>
<doc id="91000074">
<title>Multi-State Corrective Action Plan - Training Courses BLN Changes 2</title>
<date num="200910">October 2009</date>
<state>All States</state>
</doc>
</subject>
<subject>
<name>Agents Licenses</name>
<doc id="91000064">
<title>Georgia Agent Consent Orders</title>
<date num="200902">February 2009</date>
<state>GA</state>
</doc>
<doc id="91000066">
<title>New York State Correction Law</title>
<date num="200902">February 2009</date>
<state>NY</state>
</doc>
</subject>

<subject>
<name>DNC</name>
<doc id="91000063">
<title>States Prohibit Unsolicited Calls</title>
<date num="200902">February 2009</date>
<state>AL, LA, RI, UT</state>
</doc>
</subject>

<subject>
<name>LTC Partnership</name>
<doc id="91000056">
<title>Alabama Long Term Care and Long Term Care Partnership Compliance</title>
<date num="200903">March 2009</date>
<state>AL</state>
</doc>
</subject>
</compliance>

Thanks!!!