Jquery DataTable 分页不起作用我有 13 个分页,我选择第 5 个分页当我单击 GridView 中的编辑按钮时,页面将回发,并且分页不显示当前选定的(第 5)页,它将直接到第 1 页页面。当我在回发后选择分页中的任何页面时,它也是如何显示当前选定的页面
我的代码是:
<script type="text/javascript" src="DataTable/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="DataTable/jquery.dataTables.min.js"></script>
<script>
$(function () {
// Setup - add a text input to each footer cell
$('#<%=GridView1.ClientID %> th').each(function () {
var title = $(this).text();
if (title == "A Name" || title == " Name" || title == "ttl") {
$(this).html(title + '<br/><input type="text" style="width:120px" placeholder="Search ' + title + '" />');
}
else {
if (title != " ") {
//$(this).html(title + '<br/><input type="text" style="background-color:#646464;border:none" disabled="disabled" />');
}
}
});
// DataTable
var table = $('#<%=GridView1.ClientID %>').DataTable({
"paging": true,
"ordering": false,
"info": false,
"pageLength": 10,
"bLengthChange": false
});
table.columns().every( function () {
var that = this;
$( 'input', this.header() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
} );
</script>
和 Gridview :
<asp:GridView ID="GridView1" runat="server" Width="100%" CssClass="mydatagrid" HeaderStyle-CssClass="header" RowStyle-CssClass="rows" AutoGenerateColumns="false"
EmptyDataText="No files uploaded" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
<columns>
Some Columns
</columns>
</asp:gridview>
我尝试使用 StateSave:true
它只保存再次保存页面数据表未完全加载
谁能告诉我 谢谢
最佳答案
没有看到您的服务器端或文件背后的代码,我不能肯定地说您的问题就在这里。
如果您要在 Page_Load
事件中加载初始网格和值,则可能值得检查 IsPostBack
。
您的 Page_Load
应该如下所示:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//page is being loaded in response to a client postback, so do not load initial values again
//Do your initial loading of grid here
YourPopulateGridMethod();
}
}
关于javascript - Jquery DataTable 分页在回发时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41582910/