473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DataGrid: iTunes-like incremental search

Comming from Windows Forms development, I never had problems with this
issue before.

What i'm trying to achieve is an iTunes like incremental search. For
those who never used iTunes, it's basically a text field with a key
stroke event that filters the data grid as the users types in a string.
The more text in the field, the fewer fields desplayed.

The problem is that this is obviously a client side behaviour.

In windows forms, this is easily achieved with this kind of code:

private void SearchField_TextChanged(object sender, EventsArgs e)
{
string filterExpression = "Column1 LIKE '*'" + ((TextBox)
sender).Text + "'*' OR... (and so on for the rest of the columns)"
MainView.RowFilter = filterExpression;
}

In asp.net though, i fear the solution will not be as straightforward.
I would apreciate if someone had some input on how to achieve this
either by client-side script, third-party controls, etc...

Any kind of help really.

Best regards,

Luis Ferrao

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
4 2430
Luis,

On client side you don't have high-level properties like RowFilter, but you
can still make a loop that will go through the DHTML object representing the
grid, which is a table, and set the rows visibility properties according to
the text entered. You just need to find a right textbox event to handle.
onchange event fires only when you leave the textbox, not when you enter
another character. May be onkeypress?

Eliyahu

"Luis Ferrao" <lf*@undisclosed.com> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl...
Comming from Windows Forms development, I never had problems with this
issue before.

What i'm trying to achieve is an iTunes like incremental search. For
those who never used iTunes, it's basically a text field with a key
stroke event that filters the data grid as the users types in a string.
The more text in the field, the fewer fields desplayed.

The problem is that this is obviously a client side behaviour.

In windows forms, this is easily achieved with this kind of code:

private void SearchField_TextChanged(object sender, EventsArgs e)
{
string filterExpression = "Column1 LIKE '*'" + ((TextBox)
sender).Text + "'*' OR... (and so on for the rest of the columns)"
MainView.RowFilter = filterExpression;
}

In asp.net though, i fear the solution will not be as straightforward.
I would apreciate if someone had some input on how to achieve this
either by client-side script, third-party controls, etc...

Any kind of help really.

Best regards,

Luis Ferrao

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2
Isn't it possible to incorporate this behaviour in a user control so
devs don't have to implement this solution each time they want a
datagrid to behave this way?

Luis Ferrao

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3
Hello Luis,

Our new product (LiveControls for ASP.NET) is perfect for this type of
implementation. This is a suite of 20+ server controls that communicate
with the server using remote scripting (super quick communication with
web server, no browser refresh).

For your implementation, you could use a LiveTextBox and a LiveListBox.
Wire up the server-side KeyPress event of the LiveTextBox. In this
event, perform your SQL query with the value of LiveTextBox.Text. Bind
the recordset to the LiveListBox. The result, with each keystroke the
listbox contains the applicable search results...without refreshing the
page. This is cross browser too (tested in IE5+, Moz 1.3+ , Opera,
Konqueror, Galeon, etc).

Check out our tutorial app at
http://www.dart.com/livetutorial/display.aspx, or go to
http://www.dart.com/powerweb/livecontrols.asp to download a free trial.

Nov 19 '05 #4
Ok, this is what i came up with. It's inspired on someone else's code
but modified to run faster.

If you're wondering why a "setInterval" instead of a link to a "onKeyUp"
event, it's because it's still kinda slow for big (1000+ rows) table
which makes InternetExplorer freeze during keystrokes... very anoying.

It must be placed after the datagrid declaration since it refers to it.

--> If anyone could see a way to make it faster, I would apreciate the
help. It can still be a little laggy on huge tables.

Luis Ferrao

PS: Jeff, i'll have a look but it sounds nice and encapsulated the way
you put it

*******************************************
***************** CODE ********************
*******************************************
var filter = "";
var tableId = "DataGrid";
var rowHeight = 16;
var table = document.getElementById(tableId);
var rows = table.getElementsByTagName('tr');
// the following must be called at the end of declarations
var listnerInterval = setInterval("applyFilter(filter)", 1000);

function applyFilter(pattern)
{
counter = 0 // visible rows counter

// iterate through and search the array (<tr>'s)
outer_loop:
for (i=0; i < rows.length; i++)
{
if (pattern == "")
{
rows[i].className='visible'
counter++;
continue outer_loop
}
td = rows[i].getElementsByTagName('td')

// iterate through <td>'s
for (j = 0; j < td.length; j++)
{
nodeVal = td[j].firstChild.nodeValue; // gets us the #text value
of the first td tag
try {
if (nodeVal.toLowerCase().indexOf(pattern.toLowerCase ()) != -1
|| pattern == '')
{
// match found for this row (or pattern is ''), so set as
visible
// rows[i].setAttribute('class', 'visible');
rows[i].className='visible'
// increment visible rows counter but only once per row
if (j == 0) counter++
continue outer_loop
}
else {
// match not found for this row, so set as hidden
//rows[i].setAttribute('class', 'hidden');
rows[i].className='hidden'
}
} catch (ex) {}
}
}
// fix table height at the end of the loop
table.style.height = (counter * rowHeight) + "px"
}
*******************************************
***************** EOC *********************
*******************************************

Note: The search field onkeyup event must modify the filter var
obviously. But at least this way the app doesn't have to go through the
whole function between each keystroke.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jake Barnes | last post by:
I've written a PHP script that makes an RSS feed for some mp3s so that the music studio I work for can offer some of its new music as a podcast. Often, after a podcast episode has gone live, and...
1
by: Cursief | last post by:
Hello, I've been playing around a little bit with the iTunes SDK. Doing the following: iTunesApp app = new iTunesAppClass(); app.OnPlayerPlayEvent += new...
0
by: netrate | last post by:
I am trying to upload my rss xml file to Itunes, but when I go to ADD it asks for Credit Card details? I thought Itunes was free? What is going on? Here is the file :...
0
by: bar10dr | last post by:
What I want to do is get song info from iTunes if the application is running, using the ituneslib API (from Apple). One of the problem is that to check if iTunes is playing any songs I need to...
2
by: jenann50 | last post by:
hi all, i know this is probably a silly question but i dont know how to move my limewire tunes to my itunes folder so that i can download them onto my ipod. also if i have a music cd and load it...
1
by: =?Utf-8?B?a3lsMw==?= | last post by:
Hi Basically i cant install iTunes because i havn't got the reg key msmapiapps in the windows registry under Windows Messaging Subsystem. Can anyone help me to either get the key or recommend a...
3
by: Denrael | last post by:
I've been playing with the iTunes sdk on windows, and have come across a strange problem. With the following code: import win32com.client iTunes =...
1
by: =?Utf-8?B?Sk9ITg==?= | last post by:
I DOWNLOADED ITUNES THE DOWN LOAD WAS SUCCESFUL BUT I HAVE ERROR MESSAGE WHICH SAYS '' ITUNES ENCOUNTED PROBLEM AND CANNOT START.
2
by: =?Utf-8?B?YmVubnlnaQ==?= | last post by:
I can't launch iTunes 7.6 using Windows Vista Ultimate. I was using it and it was working fine until it froze up. I ended the task and now it won't launch at all. Things I have tried: 1. ...
2
by: =?Utf-8?B?TWlrZWxqTWF4?= | last post by:
I cannot download Itunes to my computer that has Windows XP Home Edition. Before it finishes downloading, this happens: "HKEY_LOCAL_MACHINE/SOFTWARE/MICROSOFT/WINDOWS/CURRENTVERSION/SHAREDDlls"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.