Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I am doing my application in MVC project. I am implementing the paging concept in my search result page. I have added the script for paging. but while running the application script is not loading in my console.
I have share my code below

<div id="sortMsg" style="text-align:center;color:Red;"></div>
        <table border="1" id="empTable" style="width:50%;removed:default">
            @if (Model != null)
            {
                if (Model.Count() != 0)
                {

                    <tbody>


                        @foreach (var item in Model)
                        {

                            <tr>
                                <td>
                                    <div class="tiptext">
                                        "font-size: large; color: rgba(26, 13, 178, 1)" class="description" src="~/Images/popup_pointer.jpg"__^

                                                        </div><hr />
                                                        <div class="description_body">
                                                            ^__b__^Description </b__^<h4 class="des">@item.BusinessDescription</h4>
                                                            ^__b__^Address2 <h4 class="des">@item.Address1</h4>
                                                            ^__b__^Email <h4 style="color:blue; margin: 5px 0px 5px 0px;">@item.EmailID </h4>
                                                            ^__b__^WorkNumber <h4 class="des">@item.WorkNumber</h4>
                                                            ^__b>MobileNumber <h4 class="des">@item.MobileNumber</h4>
                                                            ^__b>City <h4 class="des">@item.City</h4>
                                                            ^__b>State <h4 class="des">@item.State</h4>
                                                            ^__b>ZipCode <h4 class="des">@item.ZipCode</h4>
                                                            @Html.ActionLink("Book An Appointment", "CalendarView", "Appt", new { id = @item.UserID }, null)
                                                           
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>


                        }


                    </tbody>

                }
                else
                {
                    <label id="lblErrorMsg" title="Record not fount...!" style="color:red;">Record not found...!</label>
                }
            }
        </table>
    </div>

</div>

<hr />

<div id="pager" class="pager">
    <br />
    <img src="~/Content/first.png" class="first" />
    <img src="~/Content/prev.png" class="prev" />
    <input type="text" class="pagedisplay" />
    <img src="~/Content/next.png" class="next"  />

    <img src="~/Content/last.png" class="last" />
    <select class="pagesize">
        <option selected="selected" value="10">10</option>
        <option value="20">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
    </select>


C#
<script type="text/javascript">
    $(function () {
        debugger;
        $("#empTable")
        .tablesorter({ widthFixed: true })
        .tablesorterPager({ container: $("#pager") });
        $("#empTable").bind("sortStart", function () {
            $("#sortMsg").html('Sorting');
        }).bind("sortEnd", function () {
            $("#sortMsg").html('');
        });
        //Hide/delete row on click.Used live() to apply this click event for all the matching rows.
        $("#empTable img").live("click", function () {
            tablesorter_remove($(this).parent().parent(), $('#empTable'));
        });
    });
    //Start of Page Size adjust on Row Delete
    Array.prototype.remove = function (from, to) {
        var rest = this.slice((to || from) + 1 || this.length);
        this.length = from < 0 ? this.length + from : from;
        return this.push.apply(this, rest);
    };

    //repopulate table with data from rowCache
    function repopulateTableBody(tbl) {
        debugger;

        //aka cleanTableBody from TableSorter code
        if ($.browser.msie) {
            function empty() {
                while (this.firstChild) this.removeChild(this.firstChild);
            }
            empty.apply(tbl.tBodies[0]);
        } else {
            tbl.tBodies[0].innerHTML = "";
        }
        jQuery.each(tbl.config.rowsCopy, function () {
            tbl.tBodies[0].appendChild(this.get(0));
        });
    }
    //removes the passed in row and updates the tablesorter+pager
    function tablesorter_remove(tr, table) {
        debugger;
        //pager modifies actual DOM table to have only #pagesize TR's
        //thus we need to repopulate from the cache first
        repopulateTableBody(table.get(0));
        var index = $("tr", table).index(tr);
        var c = table.get(0).config;
        tr.remove();

        //remove row from cache too
        c.rowsCopy.remove(index);
        c.totalRows = c.rowsCopy.length;
        c.totalPages = Math.ceil(c.totalRows / config.size);

        //now update
        table.trigger("update");
        table.trigger("appendCache");

        //simulate user switches page to get pager to update too
        index = c.page < c.totalPages - 1;
        $(".next").trigger("click");
        if (index)
            $(".prev").trigger("click");
    }
    //End of Page Size adjust on Row Delete
</script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900