Hi,
Just started using igGrid here, and was wondering what would be the best approach to show a button for each row of data in igGrid ? for instance, I want to have a 'Copy' button for each row of data.
I've been looking around and found something called rowTemplate, but the jQuery js file kept throwing error, below is the code snippet:
@(Html.Infragistics().Grid<Matrix>() .AutoGenerateColumns(false) .ID("testGrid") .RenderCheckboxes(true) .Columns(column => { column.For(x => x.ID).HeaderText(" ").Width("80"); column.For(x => x.Description).DataType("string").HeaderText("Description"); column.For(x => x.Status).DataType("string").HeaderText("Status"); column.For(x => x.EffectiveFrom).DataType("date").HeaderText("Effective From"); column.For(x => x.EffectiveTo).DataType("date").HeaderText("Effective To"); column.For(x => x.CreatedBy).DataType("string").HeaderText("Created By"); }).RowTemplate("<tr><td>test</td><tr>").JQueryTemplating(true)
Your best option is to use feature called "Column template".
Here you can find the help topic on the subject and here you can find the sample in our samples browser.
Attached you can find sample demonstrating column template for your scenario.
Here is the grid initialization code:
In the sample I've defined template which creates button for the ProductID column. I also added data-id attribute to the button so I can later use it to identify the row from the grid. There is also a onclick handler which shows the data from the data-id attribute.
Note that you need to define template on the column from the data source(i.e. you cannot define unbound column).
Hope this helps,
Martin Pavlov
Infragistics, Inc.
Martin,
Thanks for the reply. That solution works but now I run into another problem. Once I use that Column Template feature, the boolean column that used to render checkboxes stop doing that.
Do you know why the grid is doing that ?
Hi Jeffrey Andika,
What you're observing is a known issue. The renderCheckboxes description in the API documentation states that it doesn't work when templating is enabled. In this case you should define column template and for the boolean columns in your grid.
I've updated the sample to include template for MakeFlag boolean column. I simply declare checkbox element in the template.
Here is the code for the grid initialization:
You can find the whole working sample attached to this post.
I can run your sample code just fine. However, I have the same code except I am not using the ig.loader to create the grid. When I click on one of the buttons associated with the row, my "handleCopy" method is undefined. I know it is working because I put alert(this.Id) in the onclick attribute and that works just fine. For some reason, it my event handler cannot be found.
Here's my code... as you can see I even tried passing the handler function to the function that creates the grid and that didn't work either. Any Ideas?
I found a way around the problem but it's not pretty. I defined my handler like this:
$.onDissociate = function (id_) {
// Handle dissociation here
};
And the onclick looks like this:
onclick=\"$.onDissociate(this.id)\"
It's ugly but it works.