0

I have a ASP.NET MVC 4 application using Bootstrap JavaScript and datatables to populate a list of transactions on a main page and have a link to a detail information of each transaction from the main page. Also pagination is used to page through the long list of transactions on the main page. All this works fine but when I browse to say like page 80 and click on one of the detail transaction on the main page and hit the return to transaction button on the details page I get returned to the 1st page of the main transactions instead of page 80 where I hit the entry to view details of that transaction. Is there a way to capture the current state of the pagination and return that from my return to main transactions button? Here is the ASP.NET.CSHTML view for the view history.

enter code here




@{
    ViewBag.Title = "Purchase Order History";
}

@Html.Partial("_datatables")

<div class="panel panel-primary">
    <div class="panel-heading panel-title">
        <h4>
            Purchase Order History
        </h4>
    </div>

    <div class="table-responsive" style="overflow: auto; width: 100%;">
        <table id="myTable" style="table-layout:fixed" class="table-striped">
            <thead>
                <tr>
                    <th>Ref. No.</th>
                    <th>Client</th>
                    <th>PO Num</th>
                    <th>Status</th>
                    <th></th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
</div>
<script>
    $(document).ready(function() {
        $('#myTable').dataTable({
            "bServerSide": true,
            "sAjaxSource": "AjaxHandler",
            "bProcessing": true,
            "order": [[0, "desc"]],
            "aoColumnDefs": [
                {
                    "aTargets": [4],
                    "mRender": function (data, type, row) {
                        return '<div class="btn-group btn-group">' +
                            '<a class="btn btn-default" href="Details?refNum=' + row[0] + '">' +
                            '<i class="fa fa-info-circle"></i><span class="sr-only">Details</span>' +
                            '</a>' +
                            '<a class="btn btn-default" href="Download?refNum=' + row[0] + '">' +
                            '<i class="fa fa-download"></i><span class="sr-only">Download</span>' +
                            '</a>';
                    }
                }
            ]
        });
    });
</script>

Here is the button that returns you back to the main page

<div class="btn-group btn-group-lg">
    <a class="btn btn-default" href="@Url.Action("ViewHistory")">
        <i class="fa fa-arrow-left"></i>
        <span class="sr-only">Index</span>
    </a>

Any help with this would be really really appreciated.

Thanks so much !!!!!

RickZler
  • 33
  • 8

1 Answers1

0

No matter what, you send data to server to get info of transaction. You can save this info in ViewBag. Then you should get it. I see two options to get this data: first - promise if you are good in js and second - using such thing Mix Razor and Javascript code. After then - going to right page using this https://datatables.net/plug-ins/api/page.jumpToData() (insert in document.ready after table creating)

Community
  • 1
  • 1
  • Vlad: I thought page.JumpToData() would just return column data properties and not actual jQuery page attributes. Can you please explain in more detail please. – RickZler Nov 20 '16 at 18:43
  • As I understand about this function it returns page, where we have row with some data (user name for example). So if you store this data and then will get it from server you will be redirected to neccesary page (but you should clean it on each page changing). – Vlad Bayrak Nov 20 '16 at 19:30