I am using tablesorter with pagination functionality in my partial view. The partial view is loading using ajax in view page to prevent refreshing of page. If I apply only tablesorter it works fine. But when I apply pagination with tablesorter it does not give proper output.
I have drop down list in my page and when I select value in drop down list it load data perfectly and sorting and pagination works fine as below :
But When 2nd time I select another value from drop down list. Data is not getting display.
If I only use tablesorter without pagination It works fine each time I select different value in dropdown.
What Can be reason for this?
this is my view page code :
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ApricaCRMEvent.Models.CRM.DatabaseEntities.CRM_Doctor_Request>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Search MDLNoWise
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<fieldset>
<legend>Search by MDLNo</legend>
<div id="search">
<br /><br />
Select MDLNo
<%:
Html.DropDownListFor(
model => model.Request_For_Id,
ViewData["MDLno"] as SelectList, "--Select--", new {id ="Request_For_Id" })
%>
<br /><br />
<div id="viewlist">
</div>
</div>
</fieldset>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
<link href="../../Content/Styles/blue.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$('#Request_For_Id').change(function () {
var mdlno = document.getElementById("Request_For_Id").value;
$.ajax({
url: '/Search/MDLNoDataList/',
type: "POST",
data: {
id: mdlno
},
dataType: "html",
success: function (data) {
$("#viewlist").html(data);
},
error: function () {
alert("No Records Found");
//$("#viewlist").html('No Records Found');
}
});
});
});
</script>
</asp:Content>
this is my partial view in which I use tablesorter with pagination.
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<ApricaCRMEvent.Models.CRM.DatabaseEntities.CRM_Doctor_Request>>" %>
<%--<script src="#Url.Content("../../Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="#Url.Content("../../Scripts/jquery.tablesorter.js")" type="text/javascript"></script>
<script src="#Url.Content("../../Scripts/jquery.tablesorter.pager.js")" type="text/javascript"></script>--%>
<script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.tablesorter.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.tablesorter.pager.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("table.tablesorter").tablesorter()
.tablesorterPager({ container: $("#pager"), size: $(".pagesize option:selected").val() });
});
</script>
<div>
<table class="tablesorter">
<thead>
<tr>
<th>
Request_For_Id
</th>
<th>
Territory
</th>
<th>
Estimated_Amount
</th>
<th>
Actual_Amount
</th>
<th>
Date_Created
</th>
<th>
Compute_CRM_State
</th>
<th>
Compute_Event_Type
</th>
</tr>
</thead>
<tbody>
<% foreach (var item in Model)
{ %>
<tr>
<td>
<%: Html.DisplayFor(modelItem => item.Request_For_Id)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Territory)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Estimated_Amount)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Actual_Amount)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Date_Created)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Compute_CRM_State)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Compute_Event_Type)%>
</td>
</tr>
<%} %>
</tbody>
</table>
<div id="pager" style="position: none;">
<img src="../../Content/images/first.png" class="first" />
<img src="../../Content/images/prev.png" class="prev" />
<input type="text" class="pagedisplay" />
<img src="../../Content/images/next.png" class="next" />
<img src="../../Content/images/last.png" class="last" />
<select class="pagesize">
<option selected="selected" value="1">1</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
</select>
</div>
</div>
Related
I am creating a page in jsp. Basically converting my html design into jsp page.Using Apache tomcat as a server.
My problem is I am trying to load a result page through Ajax call on form submit.I am getting "Error: Precondtion Failed" error.
Could any one resolve this error.
My code as follows
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="./css/asp.css"/>
<script type="text/javascript" src="./js/jquery-1.7.1.min.js" charset="utf-8"></script>
<title>Authorize Service Provider Search Page</title>
<script>
$(document).ready(function(){
$("form").submit(function(e) {
alert("hello");
e.preventDefault();
$.ajax({
type: "POST",
url: "aspSearchResultPage.html",
success: function()
{
$("#information").load("aspSearchResultPage.html");
},// success
error : function(xhr, textStatus, errorThrown) {
alert("Error: " + (errorThrown ? errorThrown : xhr.status));
}
});
return false;
});
});
</script>
</head>
<body class="COMPO">
<!-- Wrapper -->
<div id="wrapper">
<!-- Container -->
<div id="container" class="resolution_800x600">
<!-- Colonnage -->
<div id="colonnes" class="clear">
<!-- Page title -->
<h2 class="title_n1_orange">ASP Search Page</h2>
<!--/Page title-->
<!-- Form Page-->
<div class="form">
<form name="asp_search_page" id="form_asp_search_id" action="" method="post">
<p class="mandatory">Fields marked with asterisks (<span class="mandatory_code">*</span>) are mandatory.</p>
<table class="tables" summary="ASP Search Page" cellpadding="0" cellspacing="3">
<tbody>
<!-- First Row -->
<tr>
<th scope="row"><label for="asp">ASP <b>:</b></label></th>
<td><select id="asp" name="asp" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">ABC</option><option value="DEF">DEF</option><option value="GHI">GHI</option><option value="JKL">JKL</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select></td>
<th scope="row" colspan="2"><label for="region">Region <b>:</b></label></th>
<td><select id="region" name="region" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">APAC</option><option value="DEF">AME</option><option value="GHI">EUMA</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select>
</td>
<th scope="row" colspan="3"><label for="asp">Cluster <b>:</b></label></th>
<td><select id="cluster" name="cluster" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">INDIA&CHINA</option><option value="DEF">CHINA&JAPAN</option><option value="GHI">INDIA&HONGKONG&JAPAN</option><option value="JKL">UNITED STATES&CHILE</option><option value="MNO">CANNADA & BRAZIL</option><option value="PQR">DENMARK&EGYPT&FINLAND</option><option value="STU">EGYPT&FRANCE</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select>
</td>
</tr>
<!--/First Row-->
<!-- Second Row -->
<tr>
<th scope="row"><label for="asp">Country <b>:</b>
</label>
</th>
<td><select id="country" name="country" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">INDIA</option><option value="DEF">CHINA</option><option value="GHI">FRANCE</option><option value="JKL">PARIS</option><option value="MNO">EGYPT</option><option value="PQR">CARIO</option><option value="STU">BRAZIL</option><option value="VWX">CANNADA</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select></td>
<th scope="row" colspan="2"><label for="asp">SSC
Support <b>:</b> </label>
</th>
<td><select id="cluster" name="cluster" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">ABC</option><option value="DEF">DEF</option><option value="GHI">GHI</option><option value="JKL">JKL</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select>
</td>
<th scope="row" colspan="3"><label title="Oracle_Code" for="Oracle_Code">Oracle Code <b>:</b>
</label>
</th>
<td><input maxlength="10" name="Oracle_Code" id="Oracle_Code_id" class="field_size_e" type="text" />
</td>
</tr>
<!--/Second Row-->
<!-- Third Row -->
<tr>
<th scope="row"><label title="CC_ID" for="CC_ID">Clarify
Contract ID <b>:</b>
</label>
</th>
<td><input maxlength="10" name="CC_ID" id="CC_ID" class="field_size_e" type="text" /></td>
</tr>
<tr><td> </td></tr>
<!--/Third Row-->
<!-- Fourth Row -->
<tr>
<td colspan="2"> </td>
<td colspan="2">
<button type="submit" class="button_action_standard">
<span>Search</span>
</button></td>
<td>
<button type="reset" class="button_action_standard">
<span>Reset</span>
</button>
</td>
</tr>
<!--/Fourth Row-->
</tbody>
</table>
</form>
<!-- Content to be displayed-->
<div id="information"></div>
<!--/Content to be displayed-->
</div>
<!--/Form-->
</div>
<!--/Colonnage-->
</div>
<!--/container-->
</div>
<!--/wrapper-->
</body>
</html>
#Priya I hope you are using struts. Send your request via action and forward the request to the jsp page which you needs to be loaded. Return the same jsp page as response as data (here) and fill your div with that data. Find the code snippet below for your purpose. You need to modify the code according to your needs.
$.ajax({
url : "yourAction.do?method=yourMethod",
type : "POST",
async : false,
success : function(data) {
$("#information").html(data);
}
});
Let me know if this helps..
I have a Ajax method like this using Jquery.
function add_item()
{
item_name=$("#item_names").val()
var pars = item_name;
$.ajax({
url: "/billing/add_bill_detail",
type: "get",
dataType: "html",
data: {"pars" : pars},
success: function(returnData){
alert(returnData)
$("#aaa").append(returnData).html;
}
});
}
if i puts alert for the returnData its returning with some extra data. Like as follows.
<!DOCTYPE html>
<html>
<head>
<title>SamplePro</title>
<script src="/javascripts/jquery.js?1363935663" type="text/javascript"></script>
<script src="/javascripts/jquery_ujs.js?1363935663" type="text/javascript"></script>
<script src="/javascripts/application.js?1362549711" type="text/javascript"></script>
<script src="/javascripts/jquery.js?1363935663" type="text/javascript"></script>
<script src="/javascripts/application.js?1362549711" type="text/javascript"></script>
</head>
<body>
<tr class="tablehead">
<td>
BAB-001
</td>
<td>
BABY MASK 1
</td>
<td>
</td>
<td>
<input id="tax_rule_tax_rule" name="tax_rule[tax_rule]" size="30" type="text" value="sfdsf" />
</td>
</tr>
</br>
</body>
</html>
But the file add_bill_detail actutall contain
<% if from != "reload" %>
<tr class="tablehead">
<td>
<%=from ? item_details.item.item_code : ""%>
</td>
<td>
<%=from ? item_details.item.name : ""%>
</td>
<td>
</td>
<td>
<%= text_field 'tax_rule', 'tax_rule',:value => "sfdsf" %>
</td>
</tr>
<%end%>
</br>
Please help me to remove the unwanted Data. Thanks in Advance..
Updated Question:
i have added the follwoing scripts
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
My actual problem because of this is..
here all the values from the add_bill_detail is going under one column. it should go to 4 columns.
updated add_bill_detail code..
<table>
<tr class="tablehead">
<td>
<%=from ? item_details.item.item_code : ""%>
</td>
<td>
<%=from ? item_details.item.name : ""%>
</td>
<td>
</td>
<td>
<%= text_field 'tax_rule', 'tax_rule',:value => "sfdsf" %>
</td>
<td>
<%= text_field 'tax_rule', 'tax_rule2',:value => "vvvv" %>
</td>
</tr>
</table>
If you want to get the <tr class="tablehead"> tags, simply use the .filter() method.
alert($(returnData).filter('tr.tablehead').html()) should work!
EDIT: You are using a tr tag without the parent table tag. Hence, they get ignored in rendered HTML by the browser, browser strips off the tr tags and displays only the text. As jquery works on rendered html its behavior is the same.
Fix: Wrap your tr tags with the parent table tags and you should be good to go.
what I mean by that is:
<table>
<tr class="tablehead">
<td>
BAB-001
</td>
<td>
BABY MASK 1
</td>
<td>
</td>
<td>
<input id="tax_rule_tax_rule" name="tax_rule[tax_rule]" size="30" type="text" value="sfdsf" />
</td>
</tr>
</table>
Notice the table tag wrapping your tr tag.
How to avoid this problem in future?
Always check what your rendered HTML looks like using a tool like Inspect Element in Chrome and Firebug in firefox. If you'll do that for your table you'll notice that the tr tags get stripped by the browser.
I am passing List from Model to view , so I specified in view like this
IEnumerable. In this situation Client side validation is not firing
View :
#model IEnumerable<ShoppingCart.Models.ShoppingClass>
#{
ViewBag.Title = "Display";
}
<script src="#Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
#Html.ValidationSummary(true)
#using (Html.BeginForm())
{
<table>
<tr>
<td>#Html.Label("BrandName")
</td>
<td>#Html.TextBox("BrandName")
<div>
#Html.ValidationMessage("BrandName")</div>
</td>
<td>
<input type="submit" value="Search" name="Search" />
</td>
</tr>
</table>
}
What you've written is wrong.
You're got the view strongly typed but then you're not using the strongly typed properties or validation messages. Also, you've got the validation summary outside the form.. which won't work.
#using (Html.BeginForm())
#Html.ValidationSummary(true)
Then, you'll need to do something like this:
<table>
#foreach (ShoppingClass shoppingClass in Model) {
<tr>
<td>#Html.LabelFor(x => x.BrandName)
</td>
<td>#Html.TextBoxFor(x => x.BrandName)
<div>
#Html.ValidationMessageFor(x => x.BrandName)</div>
</td>
</tr>
}
</table>
<input type="submit" value="Search" name="Search" />
I'm not sure why you have a Search button for every item that goes to the same controller and action.. but I'll leave that for you to figure out.
Even using the unobtrusive ajax library, the scripts loaded into this page from the _Login.cshtml file are loaded when the form is submitted and I do not know how to prevent this. An even stranger effect is when an onclick event is applied to any element, when the form is submitted the script gets executed by the number of times the element was clicked.
Edit
On further testing, I realized that the unobtrusive ajax library basically re-loads the whole page inside the UpdateTargetId element, which is VERY counterproductive. This means if I submit the page 4 times, the page is loaded subsequently within each UpdateTargetId element, on each page within the page. What am I doing wrong? Is that what it's supposed to do?
#using MinervaMvc.App_Data
#model MinervaMvc.Models.LogOnModel
#{
ViewBag.Title = "Home Page";
Layout = "~/Views/Shared/_Login.cshtml";
}
<div id="loginContainer">
<h2>
Login</h2>
<div id="loginForm">
#{Html.EnableClientValidation();}
#using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "POST" }))
{
<table style="margin: 0px auto;">
<tr>
<td>
#Html.LabelFor(m => m.ServerName, new { #class = "label" })
</td>
<td>
#Html.TextBoxFor(m => m.ServerName, new { #class = "text" })
</td>
</tr>
<tr>
<td align='right'>
#Html.LabelFor(m => m.UserName, new { #class = "label" })
</td>
<td>
#Html.TextBoxFor(m => m.UserName, new { #class = "text" })
</td>
</tr>
<tr>
<td align='right'>
#Html.LabelFor(m => m.Password, new { #class = "label" })
</td>
<td>
#Html.PasswordFor(m => m.Password, new { #class = "text" })
</td>
</tr>
<tr>
<td align="right" colspan="2">
<div id='errorShade' class='shade'>
<div id='errorBox'>Password or Username is incorrect. Please try again.</div>
</div>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<div id='loginShade' class='shade'>
<input type='submit' class='button' id='btn' value='Login' /></div>
</td>
</tr>
</table>
<div id='ajaxUpdate' style='position: absolute; visibility: hidden;'>
#{if (ViewBag.Failed != null && ViewBag.Failed)
{
<script type="text/javascript">
pulseState.stopPluse = true;
hideShowLogin(true, 'errorShade', 20);
hideShowLogin(false, 'loginShade', 33);
</script>
}}
</div>
}
</div>
</div>
<br />
<div id="copywrite">
#{ Html.RenderPartial("Copyright"); }
</div>
First things first you don't need the following line:
#{Html.EnableClientValidation();}
Simply enable client validation in your web.config (should be by default):
<appSettings>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
<add key="ClientValidationEnabled" value="true"/>
</appSettings>
Then make sure that you have included the following script into your page:
jquery-1.5.1.js
jquery.validate.js
jquery.validate.unobtrusive.js
jquery.unobtrusive-ajax.js (this is for all the Ajax.* helpers to work, it has nothing to do with validation)
As far as the whole page reloading is concerned, when you specify an UpdateTargetId element in the AJAX options, this element is updated with the results of the AJAX request returned by the server (often a partial).
I have a simple view that has 2 textboxes and 1 file input.
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<iLoyalty.BackOfficePortal.Models.SegmentModel>" %>
<% using (Html.BeginForm("SaveSegment", "Segment", FormMethod.Post, new { id = "SegmentForm", enctype = "multipart/form-data" }))
{ %>
<div class="StContent">
<h3>
<%= iLoyalty.BackOfficePortal.Globals.GetResourceText("CardSegmentInsert")%></h3>
<br />
<%= Html.HiddenFor(model => model.ApplicationName, new { id = "ApplicationName" })%>
<%--<%= Html.HiddenFor(model => model.SegmentID, new { id = "SegmentID" })%>--%>
<table width="95%" border="0" cellspacing="1" cellpadding="4" class="Table" style="margin: 0 0 0 10px">
<tr class="Tr0">
<td style="width: 200px" class="Tr1">
<%= iLoyalty.BackOfficePortal.Globals.GetResourceText("ApplicationName")%>
</td>
<td>
<span id="ApplicationName">
<%= Model.ApplicationName %></span>
</td>
</tr>
<tr class="Tr0">
<td style="width: 200px" class="Tr1">
<%= iLoyalty.BackOfficePortal.Globals.GetResourceText("CardSegmentName")%>
</td>
<td>
<%= Html.TextBoxFor(model => model.SegmentName, new { id = "SegmentName", #class = "txtBox" })%>
</td>
</tr>
<tr class="Tr0">
<td style="width: 200px" class="Tr1">
<%= iLoyalty.BackOfficePortal.Globals.GetResourceText("RewardRate")%>
</td>
<td>
<%= Html.TextBoxFor(model => model.GainRate, new { id = "GainRate", #class = "txtBox" })%>
</td>
</tr>
<tr class="Tr0">
<td style="width: 200px" class="Tr1">
</td>
<td>
<input name="PostedFile" id="PostedFile" type="file" class="txtBox" style="width: 200px" />
</td>
</tr>
<tr class="Tr0">
<td class="Tr1" colspan="2" style="text-align: right">
<input id="saveBtn" type="submit" class="button" value='<%= iLoyalty.BackOfficePortal.Globals.GetResourceText("Add")%>' />
</td>
</tr>
</table>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#saveBtn').click(function () {
//BlockPage();
var options = {
target: '#contentDiv',
success: function () {
BlockDivSuccess('generalCover');
}
};
$('#SegmentForm').ajaxForm(options);
});
});
</script>
<% } %>
After clicking saveBtn I see that in debug mode it posts the appropriate data to the appropriate action and it works well. And in firebug I see the response to the ajax call is just like what I expect to have. But only in ie I get an javascript error that just says:
Microsoft JScript runtime error: Object expected
After I remove the line above, everything is ok in all browsers. But I need this too.
<input name="PostedFile" id="PostedFile" type="file" class="txtBox" style="width: 200px" />
Do you have any idea about this problem? It is interesting that it occurs only in ie.
Thanks in advance,
Just attach your Visual Studio debugger to IE process and then you can see which javascript variable is null.
Open Debug menu, choose Attach to Process..., select iexplore.exe from the list of running processes and click Attach. Make sure, that 'Attach to:' textbox says Script otherwise click Select... button and choose it.
Also make sure that script debugging is not disabled in IE.
See: http://www.jonathanboutelle.com/how-to-debug-javascript-in-internet-explorer