Может быть, вам нужно использовать columns
в $("#example").DataTable()
. Вот демонстрация работала:
Просмотр (TestDataTable):
<div>
<table id="dataList" class="table table-striped table-bordered" style="width:100%">
<thead class="thead-dark">
<tr class="table-info">
<th>id</th>
<th>name</th>
<th>age</th>
<th>phone</th>
<th>email</th>
</tr>
</thead>
</table>
</div>
@section scripts{
$('#dataList').DataTable({
ajax: {
url: '/Test/Data',
type: "get",
database: "json"
},
"processing": true, // for show progress bar
"serverSide": true, // for process server side
"filter": true, // this is for disable filter (search box)
"orderMulti": false, // for disable multiple column at once
columns: [
{ data: 'id' },
{ data: 'name' },
{ data: 'age' },
{ data: 'phone' },
{ data: 'email' }
]
})
</script>
}
TestController:
[HttpGet]
public ActionResult TestDataTable()
{
return View();
}
[HttpGet]
public IActionResult Data()
{
List<TestDT> testDTs = new List<TestDT> { new TestDT {id=1, name = "TestDT1", age = 1, phone = "1", email = "TestDT1@.com" },
new TestDT {id=2, name = "TestDT2", age = 2, phone = "2", email = "TestDT2@.com" }, new TestDT {id=3, name = "TestDT3", age = 3, phone = "3", email = "TestDT3@.com" } ,
new TestDT {id=4, name = "TestDT4", age = 4, phone = "4", email = "TestDT4@.com" }, new TestDT {id=5, name = "TestDT5", age = 5, phone = "5", email = "TestDT5@.com" } ,
new TestDT {id=6, name = "TestDT6", age = 6, phone = "6", email = "TestDT6@.com" },new TestDT {id=7, name = "TestDT7", age = 7, phone = "7", email = "TestDT7@.com" },};
return Json(new { data = testDTs });
}
результат: введите описание изображения здесь