Please look at my problem below:
请看下面我的问题:
I use in my MVC-Web-Applikation the jquery datatables. When i display only 8 columns, everything works fine. But with 1 more column, i get the ajax-error-message, see title.
我在我的mvc - web应用程序中使用jquery datatables。当我只显示8列时,一切正常。但是再多一列,我就会得到ajax-error消息,参见title。
The controller wokrs fine, because the 8 columns work fine. Here my code of the view:
控制器工作良好,因为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>
You can the, that the last columns is not active, then:
你可以,最后一列不活动,然后:
http://ziehl-abegg.com/files/work.jpg
http://ziehl-abegg.com/files/work.jpg
When i delte the // of the last column, then:
当我计算最后一列的//时,则:
http://ziehl-abegg.com/files/work_not.jpg
http://ziehl-abegg.com/files/work_not.jpg
How can i solve this problem?? Please help me... I look for a solution, since Monday, the whole day!!
我该如何解决这个问题?请帮我…我在寻找解决办法,从星期一开始,整整一天!!
Thank you.
谢谢你!
Greetz Vegeta_77
Greetz Vegeta_77
2 个解决方案
#1
5
I have it, my friends!!!!!!!!!!!!!!!!!!!!!!! Very NICE :-)
我有它,我的朋友们!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!很好:-)
Here is the Solution:
这是解决方案:
$(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" }
]
} );
} );
I had just to edit the "ajax". When you use the "type" "POST", then it works.
我只需要编辑“ajax”。当您使用“type”“POST”时,它就会工作。
Thank you very much.
非常感谢。
Greetz Vegeta_77
Greetz Vegeta_77
#2
0
Good morning. Here the HTML / table header:
早上好。这里的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>
The server side result is good, look:
服务器端结果不错,看:
http://ziehl-abegg.com/files/ServerSide.jpg
http://ziehl-abegg.com/files/ServerSide.jpg
@Sippy. I don't understand our second question.
@Sippy。我不明白我们的第二个问题。
The names are all correct, look at the third picture/link. Here is the methode "List" from the controller:
名字都是正确的,请看第三张图片/链接。以下是来自控制器的“列表”方法:
public JsonResult List([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel) { List myOriginalDataSet = dbman.View_DFS_Akustik.ToList(); List myFilteredData = dbman.Set().FullTextSearch(requestModel.Search.Value).ToList();
公共JsonResult列表([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel)列表myFilteredData = dbman.Set().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);
}
}
THX. Vegeta_77
谢谢。Vegeta_77
#1
5
I have it, my friends!!!!!!!!!!!!!!!!!!!!!!! Very NICE :-)
我有它,我的朋友们!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!很好:-)
Here is the Solution:
这是解决方案:
$(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" }
]
} );
} );
I had just to edit the "ajax". When you use the "type" "POST", then it works.
我只需要编辑“ajax”。当您使用“type”“POST”时,它就会工作。
Thank you very much.
非常感谢。
Greetz Vegeta_77
Greetz Vegeta_77
#2
0
Good morning. Here the HTML / table header:
早上好。这里的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>
The server side result is good, look:
服务器端结果不错,看:
http://ziehl-abegg.com/files/ServerSide.jpg
http://ziehl-abegg.com/files/ServerSide.jpg
@Sippy. I don't understand our second question.
@Sippy。我不明白我们的第二个问题。
The names are all correct, look at the third picture/link. Here is the methode "List" from the controller:
名字都是正确的,请看第三张图片/链接。以下是来自控制器的“列表”方法:
public JsonResult List([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel) { List myOriginalDataSet = dbman.View_DFS_Akustik.ToList(); List myFilteredData = dbman.Set().FullTextSearch(requestModel.Search.Value).ToList();
公共JsonResult列表([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel)列表myFilteredData = dbman.Set().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);
}
}
THX. Vegeta_77
谢谢。Vegeta_77