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

MVC Grid: Toolbar Template AND Insert Button

6 Answers 533 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lasse
Top achievements
Rank 1
Lasse asked on 22 Dec 2010, 11:33 AM
How do I add BOTH a toolbar template AND the Insert Command Button to the Grid?
 Calling the .Toolbar() two times like below doesn't work - probably one overwrites the other...

Html.Telerik().Grid<Address>(Model)
  .Name("AddressGrid")
  .DataKeys(keys => keys.Add(c => c.Id))
  .ToolBar(toolBar => toolBar.Template(() =>
    {
      Response.Write("Name: ");
      Response.Write(" <input type=\"text\" id=\"txtAddressSearch\" value=\"\" onkeyup=\"addressSearch()\" class=\"t-widget t-autocomplete t-input\" style=\"width: 200px; margin-top:1px;\" />");
    })
  )
  .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text))
  .Columns(columns =>
  {
    columns.Bound(a => a.Name).Width(120);
    columns.Bound(a => a.Street).Width(150);
    columns.Bound(a => a.ZipCode).Width(60);
    columns.Bound(a => a.City).Width(100);
    columns.Bound(a => a.State).Width(90);
    columns.Bound(a => a.Country).Width(90);
    columns.Command(commands =>
    {
      commands.Edit().ButtonType(GridButtonType.Text);
      commands.Delete().ButtonType(GridButtonType.Text);
    }).Width(175).Title("");
  })
  .DataBinding(dataBinding =>
  {
    dataBinding.Ajax().Select("_AddressGrid", "Address").Enabled(true)
      .Insert("_GridInsert", "Address")
      .Update("_GridSave", "Address")
      .Delete("_GridDelete", "Address");
  })
  .Selectable()
  .Editable(editing => editing.Mode(GridEditMode.InLine))
  .ClientEvents(events => events.OnRowSelect("addressOnRowSelected"))
  .Scrollable(scrolling => scrolling.Enabled(true))
  .Sortable(sorting => sorting.Enabled(true))
  .Pageable(paging => paging.Enabled(true))
  .Filterable(filtering => filtering.Enabled(true))
  .Groupable(grouping => grouping.Enabled(true))
  .Reorderable(reorder => reorder.Columns(true))
  .Footer(true)
  .Render();

6 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 17 Jan 2011, 12:58 PM
.ToolBar(toolbar => {
    toolbar.Template = "xyz";
    toolbar.Insert();
});

You should only have one .ToolBar call.  See code snippet above.
0
Lasse
Top achievements
Rank 1
answered on 18 Jan 2011, 08:48 AM
That didn't quite answer my question - How do I add BOTH a toolbar template AND the Insert Command Button to the Grid?
0
Rosen
Telerik team
answered on 18 Jan 2011, 09:52 AM
Hi Mikkel,

Indeed, having both ToolBar template and an insert button is not available. However, you can achieve similar functionality by adding a button (with the correct css classes) to the template itself, similar to the following:

.ToolBar(toolBar => toolBar.Template(() =>
{%>
      <a href="#" class="t-grid-action t-button t-state-default t-grid-add">Add new record</a>
       some other content...
<%}))

Please note that this will work only if the grid is populated through ajax binding.


Greetings,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Troy
Top achievements
Rank 1
answered on 28 Aug 2011, 11:46 PM
I too would have liked to see a more built-in solution to this. Is this feature  on the product road map? I am sure it is a very common need.
0
Carl
Top achievements
Rank 1
answered on 31 Aug 2011, 08:43 PM
0
Kien
Top achievements
Rank 1
answered on 14 Apr 2012, 09:22 AM
nice, thanks Rosen
Tags
General Discussions
Asked by
Lasse
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Lasse
Top achievements
Rank 1
Rosen
Telerik team
Troy
Top achievements
Rank 1
Carl
Top achievements
Rank 1
Kien
Top achievements
Rank 1
Share this question
or