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,
There is no column template feature out of the box, but you can use row template to accomplish your scenario.
Your code should look like this:
$(function () {
rowTemplate: "<tr><td> ${Name} </td> <td> <button type="button" onclick="showDetails(${ID})"><img width='110' height='150' src='${ImageUrl}'></img></button></td><td> <a href='${Link}'> ${Link} </td></tr>",
{headerText: "ID", key: "ID" },
In the example above I defined button for the second column. When the button is clicked it will execute showDetails function and will pass the "ID" value of the row.
Infragistics, Inc.
thanks for your response Martin.
Can i do this in razor? because i have many features enabled, but i don't know how applicate this option.
thanks again.
Yes, you can.
Here is the example which uses row templating in Razor:
<%= Html.Infragistics().Grid(Model).ID("grid1").ShowHeader(false).DefaultColumnWidth("175px") .RowTemplate("<tr><td> ${Name} </td> <td> <button type="button" onclick="showDetails(${ID})"><img width='110' height='150' src='${ImageUrl}'></img></button></td><td> <a href='${Link}'> ${Link} </td></tr>") .JQueryTemplating(true).Height("400").DataSourceUrl(Url.Action("PagingGetData")).DataBind().Render()%>
<%= Html.Infragistics().Grid(Model).ID("grid1").ShowHeader(false).DefaultColumnWidth("175px")
.RowTemplate("<tr><td> ${Name} </td> <td> <button type="button" onclick="showDetails(${ID})"><img width='110' height='150' src='${ImageUrl}'></img></button></td><td> <a href='${Link}'> ${Link} </td></tr>")
.JQueryTemplating(true).Height("400").DataSourceUrl(Url.Action("PagingGetData")).DataBind().Render()%>
In order to work in your code you should add "RowTemplate" and "JQueryTemplating" methods to your Razor code.
We have sample on the subject which you can find here:
Martin Pavlov,
Hi Martin thanks again for you response.
i have any problems, i can't show the button of the rowtemplate, this is my code.
i hope you can helpme, thanks in advance!!.
The problem is that in the row template you define 3 columns, but in the column definitions of the table you define 2 columns.
You can choose from 2 solutions:
1.Put the button in one of 2 columns you have defined.Pros:You don't have to define 3-rd column, because defining 3-rd column will need extra work(which I'll explain in the second solution).Cons: It is not visually appealing.When clicking on the button the cell will be selected which will annoy the user.
2.Put the button in its own column.This is what you did, but there is one more step. You have to define another column in the column definitions. The problem is that you cannot define custom column in the column definition so you have to duplicate the definition of one of the existing columns.For example your column definitions will look like this:
Columns(column => { column.For(x => x.idPais).DataType("string").HeaderText("idPais"); column.For(x => x.Nombre).DataType("string").HeaderText("Nombre"); @* this definition will hold the button from the template *@ column.For(x => x.idPais).DataType("string").HeaderText(""); })
Columns(column => {
column.For(x => x.idPais).DataType("string").HeaderText("idPais");
column.For(x => x.Nombre).DataType("string").HeaderText("Nombre");
@* this definition will hold the button from the template *@
column.For(x => x.idPais).DataType("string").HeaderText("");
})
<script type="text/javascript"> $(function () { $(document).delegate("#grid1", "iggridselectionactivecellchanging", function (evt, ui) { //cancel activation of the cell for column with the button if(ui.cell.index === 2) return false; }); $(document).delegate("#grid1", "iggridselectioncellselectionchanging", function (evt, ui) { //cancel selection of the cell for column with the button if(ui.cell.index === 2) return false; }); }); </script>
<script type="text/javascript">
$(document).delegate("#grid1", "iggridselectionactivecellchanging", function (evt, ui) {
//cancel activation of the cell for column with the button
if(ui.cell.index === 2)
return false;
$(document).delegate("#grid1", "iggridselectioncellselectionchanging", function (evt, ui) {
//cancel selection of the cell for column with the button
</script>
In order to hide the filter of the column which holds the buttons you can add similar code to this one:
<style type="text/css"> .hideButtonColumnFilter { display: none; } </style> <script type="text/javascript"> $(function () { // here I assume that the buttons column is the last column $("#grid1 .ui-iggrid-filtercell").last().addClass("hideButtonColumnFilter"); }); </script>
<style type="text/css">
.hideButtonColumnFilter
{
display: none;
}
</style>
// here I assume that the buttons column is the last column
$("#grid1 .ui-iggrid-filtercell").last().addClass("hideButtonColumnFilter");
Note: These workarounds cannot be done in Razor.
triffle said: Can someone point me to an example of the doing this one the client side as I'm not having much luck finding what I'm looking for...
triffle said:I did find the "features" section of the igGrid, but setting a column's "editorType" to 'button' does not produce a column of buttons.
Here's an example of my current grid: $("#SearchResults").igGrid({ autoGenerateColumns: false, columns: [ { headerText: "Id", key: "Id", width: "80px", dataType: "string" }, { headerText: "Name", key: "EntityName", width: "140px", dataType: "string" }, { headerText: "Address", key: "EntityAddress1", width: "160px", dataType: "string" }, {headerText: "City", key: "EntityCity", width: "80px", dataType: "string" }, { headerText: "State", key: "EntityState", width: "30px", dataType: "string" }, { headerText: "Zip", key: "EntityZip", width: "55px", dataType: "string" }, { headerText: "DOB", key: "DateOfBirth", width: "60px", dataType: "date" }, { headerText: "Phone", key: "HomePhone", width: "80px", dataType: "string" } ], dataSourceType: 'json', dataSource: obj, height: '300px', features: [ { name: 'Sorting', type: "local", columnSettings: [ { columnKey: "EntityName", currentSortDirection: "ascending" }, { columnKey: "SelectEntity", editorType: 'button' } ] }, ] });
Related to this, I'm simply trying to add a button column to "select" the row. Right now the row can be selected by double clicking, which then autofills out some fields on the form. Can someone point me to an example of the doing this one the client side as I'm not having much luck finding what I'm looking for... I did find the "features" section of the igGrid, but setting a column's "editorType" to 'button' does not produce a column of buttons. In fact it throws an error...
I appreciate any references, etc.
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
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.