This is a migrated thread and some comments may be shown as answers.

Toolbar custom refresh button

2 Answers 244 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
MICHAEL
Top achievements
Rank 1
MICHAEL asked on 28 Mar 2012, 10:59 AM
Hello,

I'm trying to add a custom refresh button on the tool.  I have the custom command calling a controller, but its causing an error. I just want to be able to refresh the grid.  I want to do the same thing that the refresh button thats located in the lower left hand corner does on the grid.  So I can I call that javascript from the custom command, or is there a better way to do this? I would love to just duplicate the refresh button on the top of the grid as well.  Thanks!

My toolbar:

.ToolBar(commands =>

{

commands.Insert();

commands.Custom() <-- need to call the javascript below and pass the grid name

 

 

})



my javascript:
function refreshTelerikGrid( gridName ){
     $("#" + gridName).data("tGrid").rebind();
     $("#" + gridName).data("tGrid").ajaxRequest();
 }

2 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 28 Mar 2012, 03:33 PM
Hi,

try this :

.ToolBar(commands=>
            commands.Custom().Url("#").ButtonType(GridButtonType.Text).Text("Refresh").HtmlAttributes(new { @onclick = "refreshTelerikGrid($(this).parent().parent())" }))


modify your javascript has this :

<script type="text/javascript">
function refreshTelerikGrid(grid){
     var tgrid = grid.data("tGrid");
     tgrid.rebind(); // not sure this is necessary if you are in ajax binding
     tgrid.ajaxRequest();
 }
</script>


Edit adding .Url("#") for not post the grid
0
Dimo
Telerik team
answered on 28 Mar 2012, 03:39 PM
Hi,

rebind() internally calls ajaxRequest(), so using both is not necessary. One should use only one of the methods, depending on whether the paging, sorting, etc parameters should be preserved.

Regards,
Dimo
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
MICHAEL
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or