How do you go about adding images and links to the grid. We are using asp.net with json datasource.
Thanks
Sy
Hello saevar,
If you want to use images, links etc. in igGrid you should use a feature called row template. Row template uses jQuery Templates (See http://api.jquery.com/category/plugins/templates/ ) and is enabled by setting "rowTemplate" and "jQueryTemplating" properties in igGrid.
Here is an example how to use row template for your case:
var exampleDataSource = [ {"Name": "Row 1", "ImageUrl": "http://exampledomain.com/image1.png", "Link": "http://exampledomain.com/Row1"}];
$(window).load(function () {
$("#grid1").igGrid({
autoGenerateColumns: false,
rowTemplate: "<tr><td> ${Name} </td> <td> <img width='110' height='150' src='${ImageUrl}'></img></td><td> <a href='${Link}'> ${Link} </td></tr>",
columns: [
{headerText: "Name", key: "Name" },
{headerText: "Image", key: "ImageUrl" },
{headerText: "Link", key: "Link" }
],
jQueryTemplating: true,
dataSource: exampleDataSource
});
You can see how to use row template in ASPX and Razor scenario in this sample:
http://samples.infragistics.com/jquery/grid/row-template
You can also check the following blog post which is on row templates subject, but uses igTree widget:
http://forums.infragistics.com/blogs/jordan_tsankov/archive/2011/12/02/setting-up-node-template-in-the-igtree-control.aspx
Hope this helps,
Martin Pavlov
Infragistics
hi.
i can create a column template?? I need include imagebutton for all datas in my grid for row, but is possible that issue??
thanks
Hello ckorrat,
I see that you're using igHierarchicalGrid.
There is a known bug with row template. The bug is that spaces are trimmed from the string.
This bug is already fixed and will be included in the next version of NetAdvantage for jQuery product.
As a workaround you can make string column in your data source which will resemble the column template html and in the template put the placeholder of the column:
Example:
Your row template will look like this:
and your data source should look like this:
Martin Pavlov,
Infragistics, Inc.
Hi Martin
I'm confused, I'm using iggrid, but that appears not igHierarchicalgrid.
I show, I took my data from my controller:
[GridDataSourceAction]public ActionResult Index(){ var paises = _repository.GetAllPaises(); return View("Index", paises);}
the method "GetAllPaises" look this:
public IQueryable<tblPaises> GetAllPaises() { var paises = from d in db.tblPaises orderby d.Nombre select d;
return paises; }
then I do not create my datasource, but rather I pull from my database.
I remember you my code to create the iggrid is this:
Can you help me choose the correct option to apply this RowTemplate, sorry for the inconvenience.
thank you
I think I found the solution.
jQuery MVC wrapper is one for igGrid and igHierarchicalGrid and internally creates the proper grid depending on model and settings which are set. "AutoGenerateLayouts" is the setting which is responsible for generating layouts(layouts are the nodes of igHierarchicalGrid). This setting is by default "true".
In your case I guess that your model(CxcModels.Models.tblPaises) has relationships defined and because "AutoGenerateLayouts" is by default "true" the MVC wrapper generates igHierarchicalGrid.
To fix that you should add AutoGenerateLayouts(false) to your Razor code. This way the generated code will be for igGrid. This should also resolve your template issue.
hello martin
I was able to enter the links to the grid, thanks for your help, I will share the code so others can resolve the problem, first I would like to ask you help again, I can't do is disable the filtering and sorting, as mentioned problems initially however does not work.
this is an image of iggrid:
and this is my RowTemplate:
.RowTemplate("<tr><td><img alt='Editar' onclick='editar()' src='../../../../Content/Iconos/modificarTable.png' /></td><td><img alt='Detalle' onclick='detalle()' src='../../../../Content/Iconos/consultarTabla.png' /></td><td>${idPais}</td><td>${Nombre}</td></tr>")
will have something to go with it.
Thank you very much in advance.
regards
I was able to workaround the problem.
Simply speaking you have to change the keys of the columns with links (because 3 columns has the same keys) and then use the columnSettings to disable sorting and filtering for these two columns by key.
Your code for the columns definition should look like this:
Your code for the Features definition should look like this:
Hope this helps,Martin PavlovInfragistics, Inc.
Thanks Martin.
that's work!!
this is the image of my igGrid:
Then I leave the code used, with the features: Sorting, Filtering, Selection, Row Template, Paging, plus methods to obtain the value of the selected cell.
@model IQueryable<CxcModels.Models.tblPaises>@using Infragistics.Web.Mvc;
@{ ViewBag.Title = "Catalogo de Pais"; Layout = "~/Views/Shared/_Layout.cshtml";} <script type="text/javascript">
function crear() {
var adress = '@Url.Action("Create")'; window.location = adress; }
function editar() {
var cell = $('#gridPaises').igGridSelection('selectedCell'); var dataview = $('#gridPaises').data('igGrid').dataSource.dataView(); if (cell == null) { window.alert("Debe Seleccionar un renglon de la tabla.") return; } var cellRowId = dataview[cell.rowIndex]["idPais"]; var adress = '@Url.Action("Edit")' + "/" + cellRowId; window.location = adress;
} function detalle() {
var cell = $('#gridPaises').igGridSelection('selectedCell'); var dataview = $('#gridPaises').data('igGrid').dataSource.dataView(); if (cell == null) { window.alert("Debe Seleccionar un renglon de la tabla.") return; } var cellRowId = dataview[cell.rowIndex]["idPais"]; var adress = '@Url.Action("Details")' + "/" + cellRowId; window.location = adress;
}
function eliminar() {
var cell = $('#gridPaises').igGridSelection('selectedCell'); var dataview = $('#gridPaises').data('igGrid').dataSource.dataView(); if (cell == null) { window.alert("Debe Seleccionar un renglon de la tabla.") return; } var cellRowId = dataview[cell.rowIndex]["idPais"]; var adress = '@Url.Action("Delete")' + "/" + cellRowId; window.location = adress;
} </script>
<h2>Catalogo de Pais</h2>@using (Html.BeginForm("Index", "Paises")){ <img alt="Agregar Pais" src="@Url.Content("~/Content/Iconos/AGREGARM.png")" onclick="crear()" /> <br /> <br /> @(Html.Infragistics().Grid(Model).ID("gridPaises").AutoGenerateColumns(false).PrimaryKey("idPais").FixedHeaders(true).AutoGenerateLayouts(false) .JQueryTemplating(true) .RowTemplate("<tr><td><img alt='Editar' onclick='editar()' src='../../../../Content/Iconos/modificarTable.png' /></td><td><img alt='Detalle' onclick='detalle()' src='../../../../Content/Iconos/consultarTabla.png' /></td><td>${idPais}</td><td>${Nombre}</td></tr>") .Columns(column => { column.For(x => x.idPais).HeaderText(" ").Width("30px").Column.Key = "Editar"; column.For(x => x.idPais).HeaderText(" ").Width("30px").Column.Key = "Detalle"; column.For(x => x.idPais).DataType("string").HeaderText("idPais").Width("380px"); column.For(x => x.Nombre).DataType("string").HeaderText("Nombre").Width("430px"); }) .Features(features => { features.Sorting().ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("Editar").AllowSorting(false); settings.ColumnSetting().ColumnKey("Detalle").AllowSorting(false); settings.ColumnSetting().ColumnKey("idPais").AllowSorting(true); settings.ColumnSetting().ColumnKey("Nombre").AllowSorting(true); }); features.Selection().Mode(SelectionMode.Cell).MultipleSelection(false); features.Paging().PageSize(10).FirstPageLabelText("").FirstPageTooltip("Ir a primera pagina").PrevPageLabelText("").PrevPageTooltip("Ir a pagina Anterior").ShowPagerRecordsLabel(false) .LastPageLabelText("").LastPageTooltip("Ir a Ultima pagina").NextPageLabelText("").NextPageTooltip("Ir a Siguiente pagina").PageSizeDropDownLabel("Mostrar").PageSizeDropDownTrailingLabel("Registros"); features.Filtering().FilterButtonLocation(Location.Left) .ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("Editar").AllowFiltering(false); settings.ColumnSetting().ColumnKey("Detalle").AllowFiltering(false); settings.ColumnSetting().ColumnKey("idPais").AllowFiltering(true).FilterCondition("startsWith"); settings.ColumnSetting().ColumnKey("Nombre").AllowFiltering(true).FilterCondition("startsWith"); }); }) .Height("350") .DataSourceUrl(Url.Action("Index")) .DataBind().Render() )
I hope that helps somewhat!.
Regards.
Thanks Martin