Add custom button in list view to overwrite the list view search

Hi All ,

Here what i am trying is in my list-view i want to add button near to delete option And when i click on that button called as ( New leads ) , i want to perform search with new leads and i want to display that …

*) so for adding button if i guess i need to change the ListViewGeneric.tpl file

*) and on click of that button can i call the entry point and overwrite the list-view ??

currently in my view.list.php contains code with default search of status =converted


<?php

require_once('include/MVC/View/views/view.list.php');
// require_once('custom/modules/Leads/LeadsListViewSmarty.php');

class LeadsViewList extends ViewList
{
    /**
     * @see ViewList::preDisplay()
     */
    // var $where ;
    function LeadsViewList()
    {
        parent::ViewList();             // parent listview 
    }
    public function preDisplay(){       // predisplay logic gose here 
        parent::preDisplay();
    }
    function listViewProcess()        // genrating listview 
    {
   	    $this->processSearchForm();
        if($this->where==''){
            $this->where.="leads.status='Converted'";
        }
        $this->lv->searchColumns = $this->searchForm->searchColumns;
			if(!$this->headers)
				return;
        $this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
        echo $this->lv->display();
    }

}

so how can i do it in upgrade safe manner ,
can some one please guide me on this with example i really want to learn the customization in list-view

Thank you for your time and support

You would be better off searching in the old SugarCRM forums for this info, I know it has been covered in there a few of times. Maybe this will be of help also: http://developer.sugarcrm.com/2010/11/22/howto-adding-your-own-listview-action-items/

yes i have followed this blog but in that case i will be able to select the action button if any record is selected ( or all records are ) other wise it the action button tag will be disable

so i thought of adding button near to action button tab so is there any way to

customize the tpl and trigger a query using entry point and display the list view

Thank you or the quick reply and support

love this community for that

What you suggest will be possible but I have never actually done it. Maybe this will be of help: http://forums.sugarcrm.com/f6/howto-add-custom-button-listview-34818/

Thank’s again i will try it and post if succeeded :slight_smile:

here i have tried both but in both case if we are adding script in LeadsListViewSmarty.php it will add up in acrion button tag so is there any option to add button or custom fields out side the action tab ???

we can easily add viewdefs of details and edit page but in list view is there any option available ???

Thank you for your time and support

I have not done this myself but it might be able to be done using a After_ui_frame which loads a javascript file only on this list view. you can then inject a new button anywhere on the page after the UI loads.

I don’t think adding buttons to the listviewdefs is possible. You could try extending the view.list.php of the module. And maybe “echo” before the parent->display() function.

Like this:

http://forums.sugarcrm.com/f3/add-one-button-listview-page-78131/

Yes thank you it worked but we can’t specify the location ( i mean the place ) of the button it will be always on top right ??

You could try as Ian suggested and use an After_ui_frame logic hook to inject into the page or you could add css to the form element to position it anywhere you want.

that’s fine but if i write a function to trigger a entry point which will give me the result of sql query then how can we overwrite the list view ??

thank you so much guys i really appreciate it :slight_smile:

I think the best way to do this is jusing jquery/javascript and inject the button to the page

with regards to the sql query. using a ajax call to get the results and then do something similar to display the results on the list view. ?

1 Like

for adding button both approach is working and i am calling get_rand_user entry point ( modified the entry point for testing for time being )


public function display()
     {    
        echo '<form action="index.php?entryPoint=get_rand_user" method="post" enctype="multipart/form-data">
        <p></p><h3><img src="themes/default/images/h3Arrow.gif" width="12" height="13" border="0" alt="GenerarPDF">&nbsp;Generar Listado PDF</h3><p></p>
        <input type="submit" value="Generar" name="generar" class="button">
        </form>';


         parent::display();
     }

and its coming to entry point

here in entry point i am adding this code but its not showing any thing my file name is LeadsViewList.php


<?php

echo 'boom';

class LeadsViewList extends ViewList
{

	function LeadsViewList()
    {
        parent::ViewList();             // parent listview 
    }
    public function preDisplay(){       // predisplay logic gose here 
        parent::preDisplay();
    }
    function listViewProcess()        // genrating listview 
    {
        $this->processSearchForm();
        if($this->where==''){
            $this->where.="leads.status='Converted'";
        }
        $this->lv->searchColumns = $this->searchForm->searchColumns;
            if(!$this->headers)
                return;
        $this->lv->setup($this->seed, 'custom/modules/Leads/ListView/ListViewGeneric.tpl', $this->where, $this->params);
        echo $this->lv->display();
    }
}


?>

any idea how to extend the list-view for lead module in entry point

i have also included the file include/MVC/View/views/view.list.php in the entry point

If done this way it posts to the entrypoint so you would need to redirect back.

you would be better doing a Ajax call to the entry point from the list view so it return the data to javascript then you can display a popup or push a div into the page to display the data ?

Are you just trying to generate a pdf from the entrypoint?

its working by that way i am triggering a entry point and running sql putting data in table and appending to list view thank you so much for your responses

but this way won’t be dynamic right i mean i wont we able to do action on my custom list view

so is there any way to fetch a list view in entry points for particular module using methods like listViewProcess( i mean sugar way ) ???

opps andy i was testing so i dint change the name

Thanks for your time and support

Hi All i was trying to add button in list view , and on click on that i should get
new list view with condition like ( leads.status = ’ converted ’ ) or ( leads.status = subscribers )

so what i tried is

i created a controller in custom module with action_subscriber like this


<?php
class LeadsController extends SugarController
{
	public function action_subscriber()
    {	
    	$this->view = 'sub';         
    }  
}

and i am redirection to new page view.sub.php


<?php

require_once('include/MVC/View/views/view.list.php');

class LeadsViewSub extends ViewList
{
    var $where = "leads.status='Converted'";
    function LeadsViewSub()
    {
        parent::ViewList();             // parent listview 
    }

    public function preDisplay(){       // predisplay logic gose here 
        parent::preDisplay();
    }

    public function display()
     {   
        // var_dump(__METHOD__);        
        parent::display();
     }


    function listViewProcess()        // genrating listview 
    {

        $this->processSearchForm();
        $this->lv->searchColumns = $this->searchForm->searchColumns;

        if(!$this->headers)
            return;      

        if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
            $this->lv->ss->assign("SEARCH",true);
            $this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
            $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
            echo $this->lv->display();
    }
 }

}

so i have my list ready with condition and for adding button

i have copyed the file SearchFormGeneric.tpl from include/searchForm/tpls/SearchFormGeneric.tpl and i have pasted in custom/include/searchForm/tpls/SearchFormGeneric.tpl

and i have added flollowing code in this file


<td>
	{if $module eq 'Leads'}
		<input tabindex='2' title='go_select' id='go_select' onclick='Do_action(this.form);' class='button' type='button' name='subscriber' value='Subscriber'/>
	{/if}	
</td>
......... befor help icon on search form 

and at the end i ahve added this function 

{literal}
<script type="text/javascript">
function Do_action(){
		var newLoc = 'index.php?module=Leads&action=subscriber';
		document.location.href= newLoc;
}
</script>
{/literal}

so i am getting button on basic search and on click of that button i am triggering action subscriber which will redirect to view.sub.php so its giving me thie new list as show in pic

but when i click on pagination its again running with view.list.php file with page 2

so how can i over come this problem

i think if i manage to call SUGAR.savedViews.setChooser(); function which will trigger on search button click but how can i call internal this function in coding
because if we are saving on each page manually than next time the same page will come first ??? !!!

can any one guide me on this please

thank you for your time and support

Admin any suggestion only one step far from achieving what i was trying for ??

you help will be very much appreciated

Thank you so much

:dry: