请看下面我的问题:
我在我的MVC-Web-Applikation中使用了jquery数据表。当我只显示8列时,一切正常。但是还有1列,我得到了ajax-error-message,请参阅title。
控制器工作正常,因为8列工作正常。这是我的观点代码:
<script type="text/javascript">
$(document).ready(function () {
var table = $('#example').DataTable({
"processing": true,
"serverSide": true,
"ajax": "@Url.Action("List", "DFS_Akustik")",
"columns": [
{ "data": "ID" },
{ "data": "MessID" },
{ "data": "KL_ID" },
{ "data": "MP_ID" },
{ "data": "LwLin50ss" },
{ "data": "LwLin63ss" },
{ "data": "LwLin80ss" },
{ "data": "LwLin100ss" },
//{ "data": "LwLin125ss" },
],
});
});
</script>
你可以,最后一列不活动,然后:
http://ziehl-abegg.com/files/work.jpg
当我删除最后一列的//时,则:
http://ziehl-abegg.com/files/work_not.jpg
我怎么解决这个问题??请帮助我...我寻找解决方案,从星期一开始,整天!
谢谢。
Greetz Vegeta_77
我有它,我的朋友!!!!!!!!!!!!!!!!!!!!!!!非常好 :-)
这是解决方案:
$(document).ready(function() {
$('#example').dataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "scripts/post.php",
"type": "POST"
},
"columns": [
{ "data": "first_name" },
{ "data": "last_name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
我只想编辑“ajax”。当您使用“类型”“POST”时,它可以工作。
非常感谢你。
Greetz Vegeta_77
早上好。这里是HTML /表头:
<div style="width: auto; height: 750px; overflow-x: auto; overflow-y: auto;">
<table id="example" class="table display" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>MessID</th>
<th>KL_ID</th>
<th>MP_ID</th>
<th>LwLin50ss</th>
<th>LwLin63ss</th>
<th>LwLin80ss</th>
<th>LwLin100ss</th>
@*<th>LwLin125ss</th>*@
</tr>
</thead>
</table>
</div>
服务器端的结果很好,看看:
http://ziehl-abegg.com/files/ServerSide.jpg
@Sippy。我不明白我们的第二个问题。
名称都是正确的,请看第三张图片/链接。以下是控制器中的“List”方法:
public JsonResult List([ModelBinder(typeof(DataTablesBinder))]
IDataTablesRequest requestModel)
{
List<View_DFS_Akustik> myOriginalDataSet = dbman.View_DFS_Akustik.ToList();
List<View_DFS_Akustik> myFilteredData = dbman.Set<View_DFS_Akustik>().FullTextSearch(requestModel.Search.Value).ToList();
//Apply filter to your dataset based only on the columns that actually have a search value.
foreach (var column in requestModel.Columns.GetFilteredColumns())
{
string query = column.Data + ".Contains(\"" + column.Search.Value + "\")";
myFilteredData = myFilteredData.Where(query).ToList();
}
//Set your dataset on the same order as requested from client-side either directly on your SQL code or easily
//into any type or enumeration.
bool isSorted = false;
foreach (var column in requestModel.Columns.GetSortedColumns())
{
if (!isSorted)
{
// Apply first sort.
if (column.SortDirection == Column.OrderDirection.Ascendant)
myFilteredData = myFilteredData.OrderBy(column.Data).ToList();
else
myFilteredData = myFilteredData.OrderBy(column.Data + " descending").ToList();
isSorted = true;
}
else
{
if (column.SortDirection == Column.OrderDirection.Ascendant)
myFilteredData = myFilteredData.OrderBy(column.Data).ToList();
else
myFilteredData = myFilteredData.OrderBy(column.Data + " descending").ToList();
}
}
var paged = myFilteredData.Skip(requestModel.Start).Take(requestModel.Length);
return Json(new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count()), JsonRequestBehavior.AllowGet);
}
谢谢。 Vegeta_77