Tuesday, 4 March 2014

Create Search Tool in Joomla Component


Create a search tool in Joomla component.
create a file in administrator/component/com_your_component/models/forms/fileter_formname.xmlmake sure that published and access field name is same as your database field name for this code only.
If you are use different fields than their name are must same as your database field name.
In this code I have used only published and access fields of my database.
you can use as per your requirement.


<?xml version="1.0" encoding="utf-8"?>

<form>

<fields name="filter">

<field

name="search"

type="text"

label="COM_YOUR_COMPONENT_FILTER_SEARCH_DESC"

hint="JSEARCH_FILTER"

>

<field

name="published"

type="status"

label="COM_YOUR_COMPONENT_FILTER_PUBLISHED"

description="COM_YOUR_COMPONENT_FILTER_PUBLISHED_DESC"

onchange="this.form.submit();"

>

<option value=>JOPTION_SELECT_PUBLISHED</option>

</field>

<field

name="access"

type="accesslevel"

label="JOPTION_FILTER_ACCESS"

description="JOPTION_FILTER_ACCESS_DESC"

onchange="this.form.submit();"

>

<option value=>JOPTION_SELECT_ACCESS</option>

</field>

</fields>

<fields name="list">

<field

name="fullordering"

type="list"

label="COM_YOUR_COMPONENT_LIST_FULL_ORDERING"

description="COM_YOUR_COMPONENT_LIST_FULL_ORDERING_DESC"

onchange="this.form.submit();"

default="c.title ASC"

>

<option value=>JGLOBAL_SORT_BY</option>

<option value="c.published ASC">JSTATUS_ASC</option>

<option value="c.published DESC">JSTATUS_DESC</option>

<option value="c.title ASC">JGLOBAL_TITLE_ASC</option>

<option value="c.title DESC">JGLOBAL_TITLE_DESC</option>

<option value="c.access ASC">JGRID_HEADING_ACCESS_ASC</option>

<option value="c.access DESC">JGRID_HEADING_ACCESS_DESC</option>

<option value="c.id ASC">JGRID_HEADING_ID_ASC</option>

<option value="c.id DESC">JGRID_HEADING_ID_DESC</option>

</field>

<field

name="limit"

type="limitbox"

class="inputbox input-mini"

default="25"

label="COM_YOUR_COMPONENT_LIST_LIMIT"

description="COM_YOUR_COMPONENT_LIST_LIMIT_DESC"

onchange="this.form.submit();"

>

</fields>



</form>



add below code in administrator/components/com_your_component/views/yourviewsfolder/tmpl/default.php

<form action="<?php echo JRoute::_('index.php?option=com_your_component&view=yourviews'); ?>" method="post" name="adminForm" id="adminForm">



<?php if (!empty( $this->sidebar)) : ?>

<div id="j-sidebar-container" class="span2">

<?php echo $this->sidebar; ?>

</div>

<div id="j-main-container" class="span10">

<?php else : ?>

<div id="j-main-container">

<?php endif;?>

<?php

/ Search tools bar

echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this));

?>

<?php if (empty($this->items)) : ?>

<div class="alert alert-no-items">

<?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>

</div>

<?php else : ?>

this code is creates search tool in your default view.

2 comments:

  1. This is highly informatics, crisp and clear. I think that everything has been described in systematic manner so that reader could get maximum information and learn many things.
    Web development Company in India Company | Web development Company Bangalore
    Web Development Company in Bangalore | Responsive Web development

    ReplyDelete
  2. Hi Ronak,
    Thanks for the great post, I have followed above steps and worked fine for me.
    You have mentioned whole path of file which is great and very helpful to me.
    Thanks again.

    ReplyDelete