We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Current Page and Current Selected Row

Is there an easy way to pass the current page and current row via a hyperlink to another page?  For example, I have a grid with an edit link in the last column.  I'd love to be able to send the user back to the exact page as they left when they went off to edit the record.  See code example below.

Thanks,
Brent


    Html.EJ().Grid<Litify.Web.Data.Pub>("Grid")
                .Datasource((IEnumerable<Litify.Web.Data.Pub>)Model)
                .AllowSorting()
                .AllowPaging()
                .PageSettings(p => { p.PageSize(20); p.EnableQueryString(true); })
                .AllowGrouping()
                .AllowFiltering()
                .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
                .AllowTextWrap()
                .AllowResizing()
                ///.EnablePersistence(true)
                .Columns(col =>
                {
                    col.Field(p => p.PubId).HeaderText("Id").IsPrimaryKey(true).Width(10).Add();
                    col.Field(p => p.Category).HeaderText("Category").Width(15).Add();
                    col.Field(p => p.FirstAuthor).HeaderText("First").Width(15).Add();
                    col.Field(p => p.Year).HeaderText("Year").Width(10).Add();
                    col.Field(p => p.Title).HeaderText("Title").Width(80).Add();
                    col.HeaderText("Actions").Width(10).Template("<a rel='nofollow' href='Pubs/DetailsEdit/{{:PubId}}?page={{:page}}'>Edit</a>").Add();
                })
                .Render();
}

1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team April 11, 2016 10:53 AM UTC

Hi Brent,

To pass a current page of Grid and the selected row via QueryString to another page, you can use the TemplateRefresh event. In the TemplateRefresh event, you can append the a query string to the rel='nofollow' href attribute as shown in the below code example and refer to the TemplateRefresh event Help Document.

@(Html.EJ().Grid<EmployeeView>("HierarchyGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

            . . . ..

        .Columns(col =>

        {

            col.Field("EmployeeID").HeaderText("Employee ID").Width(75).Add();

               . .  . . ..  .

            col.HeaderText("Actions").Width(20).Template("<a rel='nofollow' href='/Home/Contact'>Edit</a>").Add();

        })

        .ClientSideEvents(events=>events.TemplateRefresh("templateRefresh"))

)


<script>

    function templateRefresh(args) {

        var rel='nofollow' href = $(args.cell).find("a").attr("rel='nofollow' href");

        $(args.cell).find("a").attr("rel='nofollow' href", rel='nofollow' href + "?Page=" + this.model.pageSettings.currentPage + "&SelectedRow=" + args.rowIndex);

        //this.getRowByIndex(args.rowIndex); to get a row based on index

        //this.model.currentViewData[args.rowIndex]; to get the current data based on the index

    }
</script>


http://help.syncfusion.com/js/api/ejgrid#events:templaterefresh

We have also prepared a sample that can be downloaded from the following location.

Sample: http://www.syncfusion.com/downloads/support/forum/123680/ze/Grid_TempCol-1383763116.zip

You have quoted that would like to get back to Grid page with its state retained after performing editing action. To persist state of Grid page and other model properties, you can use enablePersistence property of Grid. While switching to Grid page after editing, the Grid will show the page where customer left. Refer to the following Help Document.

http://help.syncfusion.com/js/api/ejgrid#members:enablepersistence

Regards,
Seeni Sakthi Kumar S.

Loader.
Live Chat Icon For mobile
Up arrow icon