Author Topic: Selecting elements only in a single grid when you have nested grids  (Read 2346 times)

webifi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 45
    • View Profile
While it's not the most performant (assign a class to the elements that's unique to each grid if you need higher performance), thought I'd share the function I use to help select elements relative to a specific grid:

Code: [Select]
    function selectGridElements($grid, selector){
        // Select only the elements that are part of this grid (exclude elements that are in nested grids)
        var depth = $grid.children().first().parents(".pq-grid").length;
        return $grid.find(selector).filter(function(){
                return $(this).parents(".pq-grid").length == depth;
            });
    }

Usage:

$thisGridButtons = selectGridElements($grid,'button.my_button_class');

or:

selectGridElements($grid,'button.hello_world').click(function(){alert('Hello world')});
« Last Edit: February 10, 2015, 06:07:55 am by webifi »