я делаю что-то подобное для вас;)
см.
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var min = parseInt( $('#min').val(), 10 );
var max = parseInt( $('#max').val(), 10 );
var columntosearch = parseFloat( data[2] ) || 0; // use data for the age column
if ( ( isNaN( min ) && isNaN( max ) ) ||
( isNaN( min ) && columntosearch <= max ) ||
( min <= columntosearch && isNaN( max ) ) ||
( min <= columntosearch && columntosearch <= max ) )
{
return true;
}
return false;
});
var table = $('#example').DataTable();
// Event listener to the two range filtering inputs to redraw on input
$('#min, #max').keyup( function() {
table.draw();
} );
Вы должны добавить это к вашему виду
https://code.jquery.com/jquery-3.3.1.js
https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js
https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css
Контроллер
public ActionResult Index(){
return View();}public ActionResult LoadData()
{
List<CarModel> objCar = new List<CarModel>()
{
new CarModel {ProductBrand="BMW",ProductName="X4", ProductColor="White", Price=57000 },
new CarModel {ProductBrand="Mercedes",ProductName="AMG", ProductColor="Black", Price=61000 },
new CarModel {ProductBrand="BMW",ProductName="X6", ProductColor="Black", Price=32000 },
new CarModel {ProductBrand="BMW",ProductName="X5", ProductColor="White", Price=28000 },
new CarModel {ProductBrand="BMW",ProductName="X3", ProductColor="White", Price=30000 }
};
CarModelDetail ObjCarDetails = new CarModelDetail();
ObjCarDetails.OrderDetails = objCar;
return Json(new { data = objCar }, JsonRequestBehavior.AllowGet);
}
в поле зрения:
<table class="table table-condensed" id="countryTable">
<thead>
<tr class="table-success">
<th>ProductBrand</th>
<th>ProductName</th>
<th>ProductColor</th>
<th>Price</th>
</tr>
</thead>
JS:
var oaTable = $('#countryTable').DataTable({
"processing": true, // for show progress bar
"orderMulti": false, // for disable multiple column at once
"searching": false,
// "dom": "<<'pull-left'>'row'>Ftr<'row-fluid'<'col-md-12'lp>>",
"ajax": {
"url": "/Yourcontrollername/LoadData",
"type": "POST",
"datatype": "json"
},
"columns": [{
"data": "ProductBrand",
"name": "ProductBrand",
"width": "150px",
},
"columns": [{
"data": "ProductName",
"name": "ProductName",
"width": "150px",
},
"columns": [{
"data": "ProductColor",
"name": "ProductColor",
"width": "150px",
},
"columns": [{
"data": "Price",
"name": "Price",
"width": "150px",
},
]
});