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

[Solved] Display Row Index Number?

7 Answers 386 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sL342799
Top achievements
Rank 1
sL342799 asked on 28 May 2010, 02:02 PM
Hi All,

I am trying to display the row index number on the grid. Is there an easy way to do this? Does the 'row' object expose an index property? I tried using Index (as indicated here http://www.telerik.com/help/aspnet-mvc/p_telerik_web_mvc_ui_gridrow_1_index.html) but no luck.

Thanks!

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 28 May 2010, 02:18 PM
Hi sL342799,

Do you want it displayed server-side or client side?

Regards,
Atanas Korchev
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
sL342799
Top achievements
Rank 1
answered on 28 May 2010, 02:26 PM
Client Side would be ok
0
Atanas Korchev
Telerik team
answered on 28 May 2010, 02:36 PM
Hi sL342799,

Here is a working implementation:

<%= Html.Telerik().Grid<Order>()
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(o => o.OrderID).Title("Index").ClientTemplate("<#= ++index #>");
            columns.Bound(o => o.OrderID).Width(100);
            columns.Bound(o => o.Customer.ContactName).Width(200);
            columns.Bound(o => o.ShipAddress);
            columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(120);
        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "Grid"))
        .Pageable()
        .Sortable()
        .Scrollable()
        .Groupable()
        .Filterable()
        .ClientEvents(events => events.OnDataBinding("onDataBinding"))
%>
<script type="text/javascript">
var index = 0;
 
function onDataBinding() {
    var grid = $('#Grid').data('tGrid')
    index = (grid.currentPage - 1) * grid.pageSize;
}
 
</script>


Kind regards,
Atanas Korchev
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
ilker
Top achievements
Rank 1
answered on 16 Dec 2011, 01:05 PM
Hello,

What if you want to add sort to this index column? By this way, even you sort the rows correctly, it will still write 1,2,3,4.... to index column in all type of sorts. Can you suggest a solution for this situation ?

Regards,

Ilker.
0
Ruckumane
Top achievements
Rank 1
answered on 09 Apr 2012, 12:07 PM
could you please tell me hot to get that ClientTemplate index value in javascript.

Thanks,
Ruckumane.S
0
Acinmavi
Top achievements
Rank 1
answered on 04 Sep 2012, 02:45 AM
it's not working in GridEditMode.InLine,when the edit button press,the index number is add 1,and then,when we save ,it's added 1 again,so the index number was wrong.
Somebody has solution?
0
M Ziauddin
Top achievements
Rank 1
answered on 25 Nov 2012, 03:03 AM
Thanks, it's working! :)
Tags
Grid
Asked by
sL342799
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
sL342799
Top achievements
Rank 1
ilker
Top achievements
Rank 1
Ruckumane
Top achievements
Rank 1
Acinmavi
Top achievements
Rank 1
M Ziauddin
Top achievements
Rank 1
Share this question
or