clevertech / YiiBooster

YiiBooster
BSD 2-Clause "Simplified" License
544 stars 306 forks source link

TbExtendedGridView not filtering when fixedHeader set to true #720

Open onesource4u opened 10 years ago

onesource4u commented 10 years ago

When fixedHeader is set to true for TbExtendedGridView the filter will not work on any columns.

Found this issue in my personal project. Same issue is also on the current Yii Booster TbExtendedGridView page: http://yiibooster.clevertech.biz/extendedGridView/index.html

swedge218 commented 10 years ago

It doesnt work for me even with fixed header option commented out or set to false. Here is my code, pls correct me if i am doing a thing wrongly. Thanks

$this->widget('bootstrap.widgets.TbExtendedGridView', array(
        'cssFile' => $this->assetsPath . '/css/bootstrap.css',
        //'fixedHeader' => false,
        //'headerOffset' => 40,   // 40px is the height of the main navigation at bootstrap
        'filter'=>$model,
        'type' => 'striped bordered hover myGridView',
        'dataProvider' => $model->search(),
        'responsiveTable' => true,
        'template' => "{items}",
        'columns' => array(
                array(
                    'class'=>'CCheckBoxColumn',   
                    'selectableRows'  => 2,
                    'value' => '$data->id',
                    'checkBoxHtmlOptions' => array('name'=>'Plan[cid][]'),
                ),
        'id',
        'plan_name',
        'amount',
        'status',
                array(
                        'htmlOptions' => array('nowrap'=>'nowrap'),
                        'class'=>'bootstrap.widgets.TbButtonColumn',
                ),
    ),
    )
);
amrbedair commented 10 years ago

hi nothing wrong with your code, are you sure you are catching the params sent and filtering the result based on it?

salimionnet commented 10 years ago

current version 4.0.1 have this problem.fixed header false work and true not work.

DAMI-Michal-Bajer commented 10 years ago

It can be fixed by these steps:

  1. find file /protected/extensions/booster/assets/js/jquery.stickytableheaders.js
  2. in this file find line, which contains base.$clonedHeader = base.$originalHeader.clone(); (my line 51)
  3. after this line insert following code:
   var filters = base.$clonedHeader.find(".filters input");
   if(filters.length > 0)
      filters.removeAttr("name");

You are done. It causes, that cloned header will not have input attribute "name". So when JS serialize() is called, inputs without attribute "name" are ignored.

bravo2 commented 10 years ago

Can this fix be added to next release? Changing YiiBooster code is not the best option while using Composer to get YiiBooster and other dependencies on multiple systems including production. Since jquery.stickytableheaders.js is registered as an individual js asset (instead of a package), it cannot be overridden either.

thanks

d3artagnan commented 10 years ago

Since jquery.stickytableheaders.js is maintained in another party, so I guess it will be better to add code in TbExtendedGridView.php

idea: jquery select the clone table and remove the name attribute (see DAMI-Mike solution)

line: 692

$fixedHeaderJs = "$('#{$this->id} table.items').stickyTableHeaders({fixedOffset:{$this->headerOffset}});";`

after this line add:

            $fixedHeaderJs .= "var filters = $('#{$this->id} table.items .tableFloatingHeader').find('.filters input');
               if(filters.length > 0)
                  filters.removeAttr('name');";
            $this->componentsAfterAjaxUpdate[] = $fixedHeaderJs;

thanks to DAMI-Mike

can someone put this in the next release?

bravo2 commented 10 years ago

@d3artagnan I ended up doing the same from my page level javascript.

Ideally, jquery.stickytableheaders.js should be configured as a package in YiiBooster, similar to many other libraries included. This will allow the YiiBooster users to substitute the plugin file from application level.

lugaru90 commented 9 years ago

The Solution postet from @DAMI-Mike works for most kind of Input, but if you have a Dropdown it will not work. Use this for Dropdown and Textfields:

var filters = base.$clonedHeader.find(".filters input, .filters select");
if(filters.length > 0)
 filters.removeAttr("name");