Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How to add the client filtering function in perl table?

by GordonLim (Acolyte)
on Jun 26, 2013 at 07:50 UTC ( #1040718=perlquestion: print w/replies, xml ) Need Help??

GordonLim has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, Currently I facing a problem to add a filtering function similar as MIcrosoft excel in to my Perl script table. Previouly I wrongly post the forum need the sort for table, actually what I really need is filtering function. Anyone know is the Perl have a client filtering function? Below is the simple table I success to create my table:
open(INFO, "data.txt"); # Open db for reading @array=<INFO>; close (INFO); @ascend=sort(@array); print $status_table->header('text/html'); # create the HTTP header print $status_table->start_html('Status Table'); # start the HTML print $status_table->h1({-border=>'0', -align=>'center'},'Welcome to +Engineering Equipment List'); print $status_table->start_table({-border=>'5',-align=>'center'}); print $status_table->start_Tr({-align=>'center', -style=>'background-c +olor: #00BFFF'}); print $status_table->start_td; print 'No'; print $status_table->start_td; print 'Equipment ID'; print $status_table->start_td; print 'Description'; print $status_table->start_td; print 'Serial Number'; print $status_table->start_td; print 'Asset Tag'; print $status_table->start_td; print 'MIDA'; print $status_table->start_td; print 'Old MIDA Ref'; print $status_table->start_td; print 'Group'; print $status_table->start_td; print 'Owner'; print $status_table->start_td; print 'Location'; print $status_table->start_td; print 'Location Comment'; print $status_table->start_td; print 'Comment'; print $status_table->start_td; print 'Cost Center'; print $status_table->start_td; print 'Tagging Date'; print $status_table->end_td; print $status_table->end_Tr; foreach my $line (@ascend) { my($Equipment_ID,$Description,$Serial_Number,$Asset_Tag,$MIDA,$Old +_MIDA_Ref,$Group,$Owner,$Location,$Location_Comment,$Comment,$Cost_Ce +nter,$Tagging_Date)=split(/\|/,$line); print $status_table->start_form(-name=>'Detail', -target=>'_top', +-method=>'post', -action=>'detail.pl'); print $status_table->start_Tr; print $status_table->start_td({-align=>'center'}); print $i++; print $status_table->start_td({-align=>'center'}); print "$Equipment_ID"; print $status_table->start_td; print "$Description"; print $status_table->start_td({-align=>'center'}); print "$Serial_Number"; print $status_table->start_td({-align=>'center'}); print "$Asset_Tag"; print $status_table->start_td({-align=>'center'}); print "$MIDA"; print $status_table->start_td({-align=>'center'}); print "$Old_MIDA_Ref"; print $status_table->start_td({-align=>'center'}); print "$Group"; print $status_table->start_td({-align=>'center'}); print "$Owner"; print $status_table->start_td; print "$Location"; print $status_table->start_td; print "$Location_Comment"; print $status_table->start_td; print "$Comment"; print $status_table->start_td({-align=>'center'}); print "$Cost_Center"; print $status_table->start_td({-align=>'center'}); print "$Tagging_Date"; print $status_table->end_td; print $status_table->end_Tr; print $status_table->end_form; } print $status_table->end_table; #end the table print $status_table->end_html; # end the HTML
Thanks :)

Replies are listed 'Best First'.
Re: How to add the client filtering function in perl table?
by hdb (Monsignor) on Jun 26, 2013 at 08:03 UTC
      Sorry, I though sort table and filtering table is difference.
        And what would it do?

        Just like before, like my_sorted_fudge, you'd create a function to do stuff you want, say  my_filtered_fudge( \@array, $criteria ... ); and my_filtered_fudge would modify the array any way you please

        Apologies. I did not spot the difference between the posts.

Re: How to add the client filtering function in perl table?
by Sinistral (Monsignor) on Jun 27, 2013 at 13:05 UTC

    Since you specifically said client filtering of a table, and since your table is HTML, I believe that what you're really looking for is a way for your Perl code to generate simple HTML based on your data set and having a person's web browser do the work of sorting, filtering, and possibly editing. With that in mind, I highly recommend that you use DataTables or similar. I've used DataTables, and there is much documentation on how to do pretty styling, but more to your point, there is a built in API for column filtering.

    Current best practice for web applications is to NOT put inline attributes like fonts and colors, relying on CSS to do all styling. Furthermore, you should consider your Perl code as a data source for your tables, and use AJAX to have a web browser send requests using JavaScript and your Perl code return data, probably in a form like JSON for the JavaScript to interpret and display.

    To get started quickly, what I would do is to take your code, get rid of the inline styling, just make a syntactically correct table, have your HTML page include DataTables, and use JavaScript to quickly get your sorting and filtering working.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1040718]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2020-07-04 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?