[solved] filter functionality of CGridView not working inside a form

Problem: The filtering(search through header) of CGridView is not working when put inside a Form.

I have a view that contains a CGridView and a htmlForm around it. The sequence is

  • CHtml::beginForm()

  • Some fields (textbox, dropdown, etc.)

  • CGridView ( the one where filtering is required )

  • CHtml::submitButton

  • CHtml::endForm()

When i put some text in the filter text box and press ‘Enter’ the html form is submitted, instead of applying the filter and showing the relevant rows.However, when i remove the form from the view the search starts working.

Please let me know if i am missing something or there is another way of achieving this. Basically i need a form that contains a CGridView with working search functionality.

P.S: The sort functionality of CGridView is working fine.

Hello Gautam,

do you mean to prevent the form to submit when the user hit enter? Maybe you can disable enter key to prevent it submit the form…

I tried disabling the enter key for form, but now for search to take effect the user needs to press ‘tab’ i.e go to another field.

I want to retain the basic functionality of the filter in CGridView (the user types something and press Enter and the filtering happens)

Please let me know if i am missing someting.

If so, actually I have a good idea.

You can remove the submit button on the form. Instead of a input type submit, you put an normal input type button

and give it an onclick=‘form.submit’

a little code like this

echo CHtml::button('Submit',array('onclick'=>'submit()'));

This will fix the problem…

Thanks a ton!! Problem solved :)

sure… you are welcome :)