Yii Framework Forum: Create checkbox outside of CGridView, re-sort table (update) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Create checkbox outside of CGridView, re-sort table (update) Rate Topic: -----

#1 User is offline   Matthias Bo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 24-January 18

Posted 25 January 2018 - 04:15 PM

Hello friends,
I am using yii only recently, please excuse my ignorance. I have a table with several columns, one of which is called "score". The column "score" has several elements with the values from 10 to 0.0. I have to create several checkboxes which are positioned outside of my columns. As soon as this checkbox is clicked, the table has to sort the "scores" of, for example 10 - 9.0 without reloading the page. Next checkbox with the values 8.9 - 7.0, and so on. I'm sorry, I can't go any further.
My view looks like this:

    $this->beginWidget('zii.widgets.grid.CGridView', array(
            'dataProvider'=>$dataProvider,
            'enablePagination' => true,
            'enableSorting' => true,
            'id' => 'vul-grid-view',
            'beforeAjaxUpdate' => 'saveSelectedRows',
            'afterAjaxUpdate' => 'checkPreviouslyChecked',
            'columns' => array(
                array(
                    'header' => 'Select',
                    'class' => 'CCheckBoxColumn',
                    'selectableRows' => 2,
                    'id' => 'selectId'
                ),
                'identifier',
                 ...
                'score',
            ),
    ));


Can someone help me with that? I would be very happy. Many Thanks!
0

#2 User is offline   WyntonF 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 31-January 18

Posted 05 February 2018 - 08:43 PM

This should work for one checkbox. You will have to add the logic for multiple. Basically you refresh the gridview after you click on the checkbox. Between that you would need to implement code for your table sorting logic.
Yii::app()->clientScript->registerScript("myjqueryscript, "
 $('input:checkbox').change( function(){ // is the current checkbox checked
      if ( $(this).is(':checked') ) {
          // code to reorder table here
         $.fn.yiiGridView.update('vul-grid-view', { // refresh gridview
	   data: $(this).serialize()
        });
     }
  });
");

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users