473,399 Members | 2,146 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,399 software developers and data experts.

Sorting by column on webpage

4
I have very little experience with perl. I have a plx/tmpl page that displays a data table based on a @records array. I am able to sort the array by a subkey.

I want to create links out of the column headers then change the sort order based on what the user clicks (ascending/descending). The links change the 'sort' querystring value. I am able to get the querystring with:

Expand|Select|Wrap|Line Numbers
  1. my $sortvar = param('sort');
  2.  
I coded the tmpl file to change the link when the user clicks it, that part works fine.
I tried this in my plx page but it does not do anything:

Expand|Select|Wrap|Line Numbers
  1. if ($sortvar == '1')
  2. {
  3. my @records = map  { $_->[0] }
  4.              sort { $b->[1] cmp $a->[1] }  
  5.              map  {(my $date = $_->{COMPDATE}) =~ s/<font color="#FF0000">//;
  6.                    my ($d,$m,$y) = split(/\s+/,$date);
  7.                    $d = $d<10 ? "0$d" : $d;
  8.                    $m = $month{lc substr $m,0,3};
  9.                    [$_,"$y$m$d"]} @records;
  10. }
  11. elsif ($sortvar == '2')
  12. {
  13. my @records = map  { $_->[0] }
  14.              sort { $a->[1] cmp $b->[1] }  
  15.              map  {(my $date = $_->{COMPDATE}) =~ s/<font color="#FF0000">//;
  16.                    my ($d,$m,$y) = split(/\s+/,$date);
  17.                    $d = $d<10 ? "0$d" : $d;
  18.                    $m = $month{lc substr $m,0,3};
  19.                    [$_,"$y$m$d"]} @records;
  20. }
  21.  
Any ideas?
Feb 5 '08 #1
6 1268
KevinADC
4,059 Expert 2GB
Giving up on Tek-Tips? ;)
Feb 5 '08 #2
yesti
4
Giving up on Tek-Tips? ;)
The tek-tips site was giving me errors earlier, so I had to search for a few more forums. I'm starting to really not like perl :(
Feb 5 '08 #3
KevinADC
4,059 Expert 2GB
The tek-tips site was giving me errors earlier, so I had to search for a few more forums. I'm starting to really not like perl :(

Yea, Tek-Tips does that more than most websites, errors that is.

Not liking perl? May a foul wind blow in your general direction! ;)
Feb 5 '08 #4
yesti
4
LOL. Well many thanks to people like you that are making the experience a little better.

I see you replied to my topic on tek-tips. Waiting for that site to respond is killing me ;-P
Feb 5 '08 #5
KevinADC
4,059 Expert 2GB
LOL. Well many thanks to people like you that are making the experience a little better.

I see you replied to my topic on tek-tips. Waiting for that site to respond is killing me ;-P
In case you can't open TT:

@records is scoped wrong. When you use "my", which you should, the variables is only visible to the enclosing block, in your case the if{} elsif{} blocks. Also you don't need to quote a number to match it numerically.

Expand|Select|Wrap|Line Numbers
  1. my @sorted;#<--scoped globally
  2. if ($sortvar == 1)
  3. {
  4. @sorted = map  { $_->[0] }
  5.              sort { $b->[1] cmp $a->[1] }  
  6.              map  {(my $date = $_->{COMPDATE}) =~ s/<font color="#FF0000">//;
  7.                    my ($d,$m,$y) = split(/\s+/,$date);
  8.                    $d = $d<10 ? "0$d" : $d;
  9.                    $m = $month{lc substr $m,0,3};
  10.                    [$_,"$y$m$d"]} @records;
  11. }
  12. else {#<-- you don't really need to check the value of $sortvar here becuase if it is not 1 then this is the default sort.
  13. @sorted = map  { $_->[0] }
  14.              sort { $a->[1] cmp $b->[1] }  
  15.              map  {(my $date = $_->{COMPDATE}) =~ s/<font color="#FF0000">//;
  16.                    my ($d,$m,$y) = split(/\s+/,$date);
  17.                    $d = $d<10 ? "0$d" : $d;
  18.                    $m = $month{lc substr $m,0,3};
  19.                    [$_,"$y$m$d"]} @records;
  20. }
  21. print "$_\n" for @sorted; 
Feb 6 '08 #6
yesti
4
TT just came up before I posted this, thanks!
Feb 6 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: rmorvay | last post by:
I have successfully integrated sorting in the listview control with the following code: Private Sub ListView_ColumnClick(ByVal sender As Object, ByVal e As...
4
by: Richard | last post by:
When i try sorting in the database, it sorts the numbers: 0 1 102 2 304 305 4 etc....
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
2
by: jediknight | last post by:
Hi, I have a listview which has columns of text and columns of numerical data. I need to be able to sort these columns into ascending/desending order whenever the user clicks on the column...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
4
by: rajtalent | last post by:
hi all, I want to sort the colum when clicks the columnheader using vb.net 2005 .But i receive the following error "Error 1 Overload resolution failed because no accessible 'New' accepts...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.