Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:05:04+00:00 2026-05-14T09:05:04+00:00

I have a CGridView with columns from a table product => {‘product_id’,’category_id’,…} I have

  • 0

I have a CGridView with columns from a table "product" => {'product_id','category_id',...}
I have another table "category" => {'category_id','category_name'}

category_id is the FK in the product table.

Now i want a dropdown list of the category table and on selecting a particular value the CGridView of product should be updated to show only the rows with that category_id.
I also need the column filtering/sorting for the CGridView to work (using AJAX).

I was able to refresh the CGridView when a value is selected from the dropdown, however i am not
able to send the category_id with the ‘data’ for the CGridView:

clientScript->registerScript('search', "
$('.cat_dropdown').change(function(){
    $.fn.yiiGridView.update('order-grid', {
        data: $(this).serialize(),
    });
    return false;
});
");


The data: $(this).serialize() sends only the values that are present in the filtering text fields of the CGridView.
How do i append the category_id with it?

If the above method is not the right one, please suggest an alternative method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:05:04+00:00Added an answer on May 14, 2026 at 9:05 am

    This is how i finally did it. I dont know if the solution is optimal or not, but it works.
    Any comments welcome.

    
    

    Yii::app()->clientScript->registerScript('yiiGridView.update', "
    $.fn.yiiGridView.update = function(id, options) {
    var settings = $.fn.yiiGridView.settings[id];
    var data = {
    'product[category_id]': $('.cat_dropdown option:selected').val(),
    };
    options = $.extend({
    type: 'GET',
    data: data,
    success: function(data,status) {
    $.each(settings.ajaxUpdate, function() {
    $('#'+this).replaceWith($(data).find('#'+this));
    });
    if(settings.afterUpdate != undefined)
    settings.afterUpdate(id, data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
    alert(XMLHttpRequest.responseText);
    }
    }, options || {});
    if(settings.beforeUpdate != undefined)
    settings.beforeUpdate(id);
    $.ajax(options);
    };
    ");

    The above solution, however, needs the category_id in the columns option of CGridView. If it is removed the filtering on other columns does not work.
    If it is kept the filtering on other columns work, but the category_id is present in the grid( which is not required)
    Need a way to hide the category_id column in CGridView or some other solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a GridView bound to a DataView. Some columns in the DataView's table
I have two classes(Book,Software) that inherit from the Product class. these two classes have
I have a web user control, that has a table with 3 columns 1)
I have a gridview table that has three columns..fileID, uploadedBy and delete. Only the
I have a grid view which is used to show the Product details. Another
I'm trying to make a cgridview that can filter data from relations table. This
I have an asp.net web form. I used Gridview to display the table from
I have a simple gridview: A sql datasource to bind data from table data
I have a GridView with 10 columns. On a certain condition, I want to
I have a gridview with couple of columns,I want to achieve the following: If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.