This project is read-only.

ClientSide JavaScript

Aug 12, 2013 at 4:37 PM
This is the java script I wrote related to documentation, but I can't acces the values in the row.
<script>
        $(function () {
            pageGrids.UserIndexGrid.onRowSelect(function (row) {
                var url = '@Url.Action("Details", "UserManagement", new { id = "__id__" })';
                window.location.href = url.replace('__id__', row.UserId);
            });
        });
    
    </script>
This is the structure of my grid.
@Html.Grid(Model,GridRenderOptions.Create("UserIndexGrid")).Columns(columns =>
{
    columns.Add()
            .Encoded(false)
            .Sanitized(false)
            .RenderValueAs(d =>
                @<b>
                    @Html.ActionLink("Edit", "Edit", new { id = d.UserID})
                    @Html.ActionLink("Delete", "Delete", new { id = d.UserID })
                    @Html.ActionLink("Details", "Details", new { id = d.UserID })
                </b>);
 
    columns.Add(o => o.UserFirst)
            .Titled("First Name").Filterable(true);

    /* Adding "CompanyName" column: */
    columns.Add(o => o.UserLast)
            .Titled("Last Name")
            .ThenSortByDescending(o => o.UserID).Filterable(true);

    columns.Add(o => o.UserEmail)
            .Titled("Email").Filterable(true);
      
    columns.Add(o => o.RoleId)
           .Titled("Role Name").Filterable(true)
           .RenderValueAs(o => CustomRenderingOfColumn(o));
 
    columns.Add(o => o.isPreparer)
            .Titled("Is Preparer?").Filterable(true);

    columns.Add(o => o.isSalesRep)
            .Titled("Is SalesREP?").Filterable(true);

}).WithPaging(5).Sortable(true).Filterable(true).WithMultipleFilters()
But when i select a row in grid, i take this error.

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'RoadTex.Controllers.UserManagementController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters


How can i use the row values in jquery?

Thanks.
Aug 12, 2013 at 5:06 PM
Hi,

Client row have only column properties that you added to the grid. If you want use row.UserId you need to add this column to the grid. If you want that column was not displaying - you can mark column as hidden:
columns.Add(o => o.UserId, true)
Aug 12, 2013 at 5:23 PM
I add the UserId column but it is still giving the same error.

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'RoadTex.Controllers.UserManagementController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters


I can't access none of the row column values. Not only row.UserId.

Thanks.
Aug 12, 2013 at 5:34 PM
which version of the grid you are using? Which url redirect when you click on the row?
Try to debug client code, use developer tool for that (F12). Try to log url row variable:
pageGrids.UserIndexGrid.onRowSelect(function (row) {
                var url = '@Url.Action("Details", "UserManagement", new { id = "__id__" })';
                console.log(row);
                console.log(url );
            });
Aug 12, 2013 at 6:14 PM
Thanks for everything.
It says Uncaught ReferenceError: row is not defined

What should i do the define the row?
Aug 12, 2013 at 6:19 PM
it looks very strange, row defined as argument, and should passed to the grid.

what console logs?
try to update for grid 3.0beta - https://www.nuget.org/packages/Grid.Mvc/3.0.0-beta and use
pageGrids.UserIndexGrid.onRowSelect(function (e) {
                var url = '@Url.Action("Details", "UserManagement", new { id = "__id__" })';
                window.location.href = url.replace('__id__', e.row.UserId);
            });
Aug 12, 2013 at 6:25 PM
I didn't make the update but it worked with the code you wrote.

Thank you very much.
Aug 12, 2013 at 6:27 PM
It seems that you are using v 3.0 beta, which not released yet
Aug 12, 2013 at 6:34 PM
Edited Aug 12, 2013 at 6:39 PM
Thanks for your time. I really appreciated.