Advertisement:

Author Topic: [Tutorial] Enable shift-multiple select in osclass Dashboard  (Read 3467 times)

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Hi Everyone,
This is my latest tutorial to enable multiple select while pressing shift key. It means after following this tutorial, if you will select a listing (or comment ) in admin dashboard and after that select another listing while pressing shift key than all in between listings will be selected automatically.
Same happen when you want to uncheck multiple listing via mouse and shift key.
I am running this code from 5 months and it is working fine but I may not guarantee if you will get electric shock while adding this code to your site. 

So what you have to do? Just add this code to your functions.php file which you can find in your theme directory.
Code: [Select]
<?php function checkbox_admin_header() {
?>

<script type="text/javascript">
        (function($){
  function toggleSelected(element, shouldSelect) {
    $(element).attr("checked", shouldSelect);
    if(shouldSelect){
        $(element).parents("tr").addClass("selected");
    } else {
        $(element).parents("tr").removeClass("selected");
    }
  }
 
  $.fn.shiftSelectTable = function(){
    var $table = $(this);
   
    $table.find(":checkbox").click(function(event){
      var last = $table.data("jquery-shift-select-table.last");
      $table.data("jquery-shift-select-table.last", $(this).get());
     
      if(last == null || !event.shiftKey) {
        $(this).parents("tr").toggleClass("selected");
      }
      else {
        var shouldSelect = $(this).attr("checked");
        if(shouldSelect===undefined){
            shouldSelect=null;
        }
        var $checkboxes = $table.find(":checkbox");
        var currentIndex = $checkboxes.index(this);
        var lastIndex = $checkboxes.index($(last));
        var $checkboxesToChange = (currentIndex >= lastIndex) ? $checkboxes.slice(lastIndex, currentIndex+1) : $checkboxes.slice(currentIndex, lastIndex+1);
       
        $checkboxesToChange.each(function(){
          toggleSelected(this, shouldSelect);
        });
      }
    });
   
    this.find(":checked").parents("tr").toggleClass("selected");

    return this;
  };
})(jQuery);
$(function() {
      $(".table").shiftSelectTable();
    });
    </script>
<?php 
osc_add_hook('admin_header''checkbox_admin_header');

?>

While pasting this code keep note of php start end tag :
Code: [Select]
<?php  ...............      ?>
I hope you all will like it.
Regards
Navjot Tomer

PS: Tuffclassified theme user can add it to custom-functions.php via php editor included in theme dashboard. Or you can wait for next version I will include it in next version.
« Last Edit: July 02, 2013, 03:04:25 pm by navjottomer »

strata

  • Sr. Member
  • ****
  • Posts: 411
  • Always good, always...
Re: [Tutorial] Enable shift-multiple select in osclass Dashboard
« Reply #1 on: July 02, 2013, 02:56:55 pm »
Thank you for this tutorial  navjottomer, I will wait for the next one :)

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Re: [Tutorial] Enable shift-multiple select in osclass Dashboard
« Reply #2 on: July 02, 2013, 02:58:31 pm »
Thank you for this tutorial  navjottomer, I will wait for the next one :)

Thanks Strata, I hope that I will keep up.  :)

zoopla

  • Guest
Re: [Tutorial] Enable shift-multiple select in osclass Dashboard
« Reply #3 on: February 09, 2014, 06:56:44 am »
Very useful! Thanks