View Full Version : Client side Recordset managing
Mad Max
08-27-2003, 08:58 AM
Hi,
I know that is possible to build an ASP page that performs a query (server side) and sends the resulting Recordset to an array on the client computer (e.g. in order to display a table).
But my question is:
can we use JS to manipulate and display the array (sort, split, etc.), based on user mouse clicks, without new server request (i.e. without make a new query)?
A simple page refresh will cause the ASP page to be re-executed (and so the query).
An array sorting, based on click event, doesn't update the display.
Thank you in advance.
As far as I know:
1. Yes, you can use JS to sort any data, as long as thay are already "built in" page by a server-side application from a database.
Perhaps it will be most eficient to use a database manager such as XML and dispaly them with XMLDOM... Well, this is rather new for me, a confess :-))
2. No, a simple refresh will not rexecute te ASP (even I think that it depends on the application...I reckon)
3. Javascript is a pure cilent-side application. It manages all the data ALREADY sent by a server-side, and nothing but those data. The only way to ask for a rexecution or a refresh from a database is to send a SUMBIT HTML comand (GET) or use a similar Javascript method to do so...
Well, if anyone has detailed information about that, I will glad to learn more about... I am very interested also in that matter (even I work mostly with php/MySQL :-)))
glenngv
08-27-2003, 09:48 AM
<script type="text/javascript">
var arr = new Array();
<%
i = 0
while not rs.EOF
response.write "arr[" + i "] = new Array();" & VbCrLf
response.write "arr[" + i "][0] = " & rs("fieldNameNumber") & ";" & VbCrLf
response.write "arr[" + i "][1] = '" & rs("fieldNameString") & "';" & VbCrLf
'add as many fields in each record
i = i + 1
rs.movenext
wend
%>
</script>
the generated javascript would be an associative array (array of arrays):
<script type="text/javascript">
var arr = new Array();
arr[0] = new Array();
arr[0][0] = 1;
arr[0][1] = 'some string';
arr[1] = new Array();
arr[1][0] = 2;
arr[1][1] = 'some string again';
//...
</script>
With that, you can display and manipulate the array
Mad Max
08-27-2003, 09:51 AM
Thanks to Kor for the very rapid answer.
I already built the ASP pages to accomplish this task: when the user selects one column of the table, the same ASP page is called with the new parameter in the querystring:
myapage.asp?column='xxxx'
and 'xxxx' is used, on server side, to make a new query with the 'ORDER BY xxxx' option.
But my purpose is different: why to re-execute the query when the client computer already keeps the whole array? I would like to use client side scripting to re-arrange the table many times without call the main ASP page again.
glenngv
08-27-2003, 10:10 AM
or you can use literal notation:
var arr = [
[1, 'some string'],
[2, 'some string'],
[3, 'some string']
];
This is the same array as in the previous code I posted.
http://www.codingforums.com/showthread.php?s=&threadid=24659
Mad Max
08-27-2003, 10:25 AM
If I have understood glenngv interesting solution, when the page is loaded I have to prepare, on client side, an array of arrays (one for each possible table sorting order) and then update the visualization based on user's choice.
Let me specify:
1- I don't have a fixed number of columns for the table (it depends on the dynamic query I make), so the array preparation can consume a lot of server resources (I also expect many connections at the same time and big tables...)
2- I can build a single array of objects, then I can use the '.sort' method to do the job (I know how to do it) but the problem remains: how to refresh the table without refresh the page?
glenngv
08-27-2003, 10:37 AM
1 - if the records are too many, you have to set a maximum display per page like this forum does.
2 - http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=sortable+table
Vladdy
08-27-2003, 11:46 AM
http://www.vladdy.net/webdesign/DOM_Tables.html
Be aware that using this method the visitor gets nothing if javascript is disabled. It can certainly be adapted so that the data is sent in the HTML table.
In select browsers you can also get new data from database without refreshing the page using background server polls (http://www.codingforums.com/showthread.php?s=&threadid=16205)
Mad Max
08-27-2003, 01:20 PM
OK, I have it.
Thanks to glenngv and Vladdy for the links. :) :) :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.