YiiBooster icon indicating copy to clipboard operation
YiiBooster copied to clipboard

TbExtendedGridView sortableRows callback faulty

Open nexflo opened this issue 12 years ago • 7 comments

this widget is not outputting the position, this happens on the official YiiBooster site as well once u look at the console log.

$this->widget('bootstrap.widgets.TbExtendedGridView', array(
    'sortableRows'=>true,

sortable doesnt return position.

id: [object Object], position:undefined 

nexflo avatar Mar 05 '13 16:03 nexflo

Running into the same issue, this might help us: https://github.com/clevertech/YiiBooster/issues/50 & https://github.com/clevertech/YiiBooster/pull/55

defunctl avatar Mar 06 '13 01:03 defunctl

I'm having the same issue i've been investigating under these files, and i found something:

on file "TbExtendedGridView" there is a function called "renderKeys" that is suppose to create a hidden tag with the value of position tag. this tag is used by file "jquery.sortable.gridview.js" to generate json that is returned to the view, so you can update rows positions.

but, has far as i can dig on it, function "renderKeys" is not called anywhere, maybe this is the problem?? because HTML generated by widget doesnt have tag "data-order".

i'll continue investigating, and try to fix it....

soyoh avatar Mar 12 '13 12:03 soyoh

@soyoh , I had the same problem as you, but I've finally managed it. The problem is that yii-booster's documentation is not reflecting the latest changes in sortableRows functionality. You were right that when you follow the sample code, data-order attribute is not being generated. This is because you didn't define sortableAttribute and the rest of the renderKeys function hasn't been executed.

In the current version, sorting is pretty much automatic and you just need to define database attribute which stores the sorting position. This attribute has to be larger than 0 (thus set correctly on creating the database item). Updating can be implemented manually in afterSortableUpdate or you can make use of the TbSortableAction, which will do it for you.

My working solution looks like this:

$this->widget('bootstrap.widgets.TbExtendedGridView', array(  
    'sortableRows' => true,
    'sortableAttribute' => 'position',
    'sortableAjaxSave' => true,
    'sortableAction' => 'xadmin/xgallery/gallery/imageSortable',
    'afterSortableUpdate' => 'js:function(){}',
    'type'=>'bordered',    
    'dataProvider' => $images,
    ....
));

Controller

public function actions() {
    return array(
        'imageSortable' => array(
        'class' => 'bootstrap.actions.TbSortableAction',
        'modelName' => 'GalleryImage'
    ));
}

zvonicek avatar Mar 24 '13 09:03 zvonicek

Not a bug, documentation for sorting outdated.

magefad avatar Mar 29 '13 13:03 magefad

I'll update the docs when I'll have a chance.

hijarian avatar Mar 30 '13 13:03 hijarian

@hijarian : Can you please update the documentation ? today i almost spent 5 , 6 hours looking for information , asking in irc and digging classes and finally i reached here to create an issue and found the solution above, Btw i have created a how-to and posted on my blog : http://hasan.es/sortablerows-saving-postions-tbextendedgridview-yiibooster/

H45AN avatar Jan 28 '14 17:01 H45AN

@fromYukki Please, can you do this relatively simple change? Just put the explanations from @zvonicek to the "Extended Grid View -> Sortable Rows" subsection, replacing what was there before. Most problem is to rewrite the example so it'll use whatever models are available on the documentation website.

Everyone, please, understand, that the TbExtendedGridView, while being most bug-ridden and otherwise badly constructed widget from the whole YiiBooster, is at the same time the least maintained widget. Given that we have only one maintainer currently (and it's not me), it's either that unbearable migration to Twitter Bootstrap 3 or the bugfixing in the Extended Grid View.

hijarian avatar Jan 29 '14 09:01 hijarian