saman0 / flexicontent

Automatically exported from code.google.com/p/flexicontent
0 stars 0 forks source link

Search/filter/sort functions propose solution #129

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
you can see solution here
http://flexicontent.org/forum/index.php?f=25&t=2139&rb_v=viewtopic

"Download http://www.joostdevalk.nl/code/sortable ... rtable.zip
put unzipped 'sortable.js' into …/components/com_flex…/assets/js/
set proper rights
put arrow images into …/images/stories/

add into new line #33 of 'category_items.php' of your template

Code: Tout sélectionner
    <script type="text/javascript" src="<?php echo JURI::base().'components/com_flexicontent/assets/js'.DS?>sortable.js"></script>

change class param in line #90 - same file to

Code: Tout sélectionner
    <table class="sortable flexitable" id="flexitable" 

adjust the path to the arrow images in 'sortable.js' around line #12

add into new line #33 of 'category_items.php' of your template

Code: Tout sélectionner
    <script type="text/javascript" src="<?php echo JURI::base().'components/com_flexicontent/assets/js/sortable.js'?>"></script>

et voilà - the category-view is sortable

OK a q&d solution to give an idea how to adjust the date sort function to other 
formats.
We use a single field for date+time the european way - 'dd.mm.yy - HH:MM Uhr' - 
looks like 31.12.10 - 23:59 Uhr

Change the regex pattern in line #119, 120 of sortable.js to -

Code: Tout sélectionner
    if (itm.match(/^(\d{2}?)[\/\.\-]\s?([a-zA-z]{2,9}?)[\/\.\-]\s?(\d{2,4}?).*$/)){sortfn = ts_sort_date;}
    if (itm.match(/^(\d{2}?)[\/\.\-](\d{2}?)[\/\.\-](\d{2,4}?).*/)){sortfn = ts_sort_date;}

…just to be a bit more flexible

…append an additional 'else if' block to line #238 -
//we use the date/time separating dash in our format as anchor. Adjust it to 
whatever you need

Code: Tout sélectionner
       } else if (date.substr(9,1) == '-') { // we use the date/time separating dash in our format as anchor
          if (europeandate == false) {
             // yyyy.mm.dd - HH:MM:SS
             dt = date.substr(6,4)+date.substr(0,2)+date.substr(3,2)+date.substr(13,2)+date.substr(16,2)+date.substr(19,2);
             return dt;
          } else {
             // 31.12.10 - 23:59 Uhr => 1012312359
             dt = date.substr(6,2)+date.substr(3,2)+date.substr(0,2)+date.substr(11,2)+date.substr(14,2);
             return dt;
          }

copy the following javascript function into the 'category_items.php' of your 
flexicontent template (around line #32) -

Code: Tout sélectionner
       function filter_table( phrase, _id ) {
          var words = phrase.value.toLowerCase().split(" ");
          var table = document.getElementById(_id);
          var ele;
          for (var r = 1; r < table.rows.length; r++){
             ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
             var displayStyle = 'none';
             for (var i = 0; i < words.length; i++) {
                if (ele.toLowerCase().indexOf(words[i])>=0) {
                    displayStyle = '';
                } else {
                      displayStyle = 'none';
                   break;
                }
             }
             table.rows[r].style.display = displayStyle;
          }
       }

change the <div class="fc_fleft"> - block to

Code: Tout sélectionner
       <div class="fc_fleft">
       <input name="filter" id="filtr" onkeyup="filter_table(this, 'flexitable', 1)" type="text">
    <!--//      <input type="text" name="filter" id="filter" value="<?php echo $this->lists['filter'];?>" class="text_area" onchange="document.getElementById('adminForm').submit();" />-->
    <!--//      <button onclick="document.getElementById('adminForm').submit();"><?php echo JText::_( 'FLEXI_GO' ); ?></button>-->
    <!--//   <button onclick="document.getElementById('filter').value='';document.getElementById('adminForm').submit();"><?php echo JText::_( 'FLEXI_RESET' ); ?></button>-->
       <label for="filtr">Search</label>
       </div>

(we keep the original code because you never know)
et voilà - you can even use more than one keyword (AND)

And don't forget to activate the search field in your category params

The javascript is from http://www.vonloesch.de/node/23
Give him the credits, the honour and your recognition. Me the money 'nd love :D
And here is an extension http://leparlement.org/filterTable
Someone out there who brings in the 'string OR string' function?

Hi im stuck with this "Search" problem
for a week and now im just solve my problem ,
May be help any one .

Im just add php code in "models/categories.php"
Line 337
From

Code: Tout sélectionner
    $where .= ' AND LOWER( i.title ) LIKE '.$this->_db->Quote( '%'.$this->_db->getEscaped( $filter, true ).'%', false );

To be

Code: Tout sélectionner
                $where .= ' AND ( LOWER( i.title ) LIKE '.$this->_db->Quote( '%'.$this->_db->getEscaped( $filter, true ).'%', false );
                $where .= ' OR LOWER( ie.search_index ) LIKE '.$this->_db->Quote( '%'.$this->_db->getEscaped( $filter, true ).'%', false );
                $where .= ' ) ';

Caz old sql doesn't search in others field ,

BUT Still have problem when searching return more than one page , When i change 
page , Search result will lost . T T , In this case i can't solve.

How can i pass filter value to next page ?
"

Regards

Original issue reported on code.google.com by mic...@free.fr on 26 Apr 2011 at 11:30

GoogleCodeExporter commented 9 years ago
I think this method could be easily implemented in a template. I did something 
similar for a client already. But we need to find a more generic solution as 
the JS solution cannot be applied to multipage category views ;)

Original comment by emmanuel...@gmail.com on 27 Jun 2011 at 5:16