Forum Moderators: open

Message Too Old, No Replies

spry dataset filter

Any tips on speeding it up?

         

Demaestro

9:21 pm on Aug 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have some pages that use Spry datasets to display data.

I have added a non-destructive filter to it and it has reached over 600 rows and is starting to hang.

Does anyone have any XP with Spry datasets and filters?

Any tips on speeding this up?

Data Sets
var dsSubscribers = new Spry.Data.XMLDataSet("list_man.py/getSubscribers?ran=" + randomString(), "data/row",{useCache:false, sortOnLoad: "first_name"});

var pv1 = new Spry.Data.PagedView(dsSubscribers, {pageSize:25, forceFullPages:false, setCurrentRowOnPageChange:false, useZeroBasedIndexes:true});

Filter Input:
<input type="text" id="sub_filter" onKeyUp="dsSubscribers.filter(FilterData);" />



JS:

var search_field = 'first_name'

function FilterData() {
var filter_val = document.getElementById('sub_filter').value;
if (filter_val == ''){dsSubscribers.filter(null);return;}
var re = new RegExp("^" + filter_val, "i");
var myFilterFunc = function(dataSet, row, rowNumber) {
if(row[search_field].search(re) != -1) {return row;} else {return null;}
}
dsSubscribers.filter(myFilterFunc);
}

alias

10:24 am on Aug 23, 2010 (gmt 0)

10+ Year Member



From the code point of view I see nothing exceptionally wrong with your code, only possible optimizations here and there.

The only part that is slow is the recurring iteration through the whole dataset each time the event is triggered.

So you should think on how to optimize and decrease the dataset you need at a particular moment in time.

One thing you should definitely do, is store the successful matches for each keyup in a temporary array, so, technically, when another keyup happens AND a character is added to the end of the previous value, you do not iterate the whole data set, you iterate only the previously matched values -- which makes sense, doesn't it? This approach would require a bit more logic, but it is a right way to do it in this case.

And, as a general approach, I believe your dataset is alphabetic -- in which case it would make sense to create your own custom index, splitting up the big datasets into smaller once based, for example, on the first character of the item.

Demaestro

9:25 pm on Aug 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



alias,

great suggestion on the storing of matches, I am going to try to implement that.

I also added a delay on calling the filter by calling a function that calls the filter after a time of non typing, that way if they type 'henry' and do it with not too much time between keystrokes it won't draw the HTML 5 times, it will only draw it once.

function StartFilterTimer()
{
if (StartFilterTimer.timerID)
clearTimeout(StartFilterTimer.timerID);
StartFilterTimer.timerID = setTimeout(function() { StartFilterTimer.timerID = null; FilterData(); }, 100);
}


I am wondering if Jquery does xml filtering like this but with less overhead?