Hello,
I need to make an entire row be a link. How can I do this in iggrid?
Thanks.
hi Jessica,
you can use column templates in order to make every cell text point to the same URL, so no matter where they click, the grid will navigate to that row. Also , you can bind an event handler for every row, which, based on the primary key value (or some other field in the row?) , navigate to a different URL, something like:
$("#grid1").find("tr").on("click", function () {
// use primary key (data-id attribute), to lookup the data record from the data source, or some other info, in order to navigate to a URL
});
Hope it helps. Thanks,
Angel
what do you mean by // use primary key (data-id attribute), to lookup the data record from the data source, or some other info, in order to navigate to a URL?
Can you give me an example?
Thanks
Hi Jessica,
Attached you can find sample which implements clicking on a grid row and navigating to another Url.
The Url contains parameters taken from the grid data source.
Hope this helps,
Martin Pavlov
Infragistics, Inc.
Clicking the entire row works. But I can't get the parameters to work.
$("#thisGrid").find("tr").live("click", function (event) {
var rowId = $(event.currentTarget).attr("data-id");
var dataRecord = $("#thisGrid").data("grid").dataSource.findRecordByKey(parseInt(rowId));
window.location.href ="http://google.com?g=" + dataRecord.DocumentId;
But it gives me a compilation error "CS0103: The name 'dataRecord' does not exist in the current context "
Also, I'm using razor. Maybe I'm just missing something
@(Html.Infragistics().Grid<DocumentsGridViewModel>().ID("thisGrid")
.Columns(column =>
{...
dataRecord is a JavaScript variable so it should not have anything to do with C# compilation.
You should check if the button click code is enclosed in html SCRIPT tag so it doesn't interfere with C# code.
It is enclosed i scrip tags. And it compiles just fine. At run time though, when I click on the row, it gives me that error. I think it cannot find the datarecord that I was referring to.
Can you provide sample code with grid chaninig configuration?
Best regards,
You mean this?:
{
column.For(x => x.DocumentId).DataType("int").HeaderText("Doc Id").Width("70px").Template("<a href='?IDNumber=${DocumentId}&documentType=${DocumentType}&companyId=${CoId}> ${DocumentId} </a>");
column.For(x => x.CompanyId).DataType("int").HeaderText("Partner").Width("130px");
column.For(x => x.DocumentType).DataType("string").HeaderText("Doc Type");
column.For(x => x.Date).DataType("int").DataType("date").Format("MM/dd/yyyy hh:mm:ss tt").HeaderText("Date").Width("100px");
column.For(x => x.StatusDescription).DataType("string").HeaderText("Status").Width("100px");
column.For(x => x.Key).DataType("string").HeaderText("Key").Hidden(true);
})
.Features(feature =>
feature.Paging().PageSize(10);
feature.Resizing().AllowDoubleClickToResize(true).DeferredResizing(false);
feature.Sorting().Mode(SortingMode.Single).ColumnSettings(settings => settings.ColumnSetting().ColumnKey("DocumentId").AllowSorting(true));
.Width("100%")
.Height("320px;")
.DataSourceUrl(Url.Action("GetDocumentList", new {searchProcessed = ViewBag.SearchProcessed, query = ViewBag.Query}))
.ClientDataSourceType(ClientDataSourceType.JSON)
.DataBind()
.Render()
)