필터링을 위해 콤보 상자가 들어있는 XML 데이터를 표시하기 위해 DataTables 을 사용하고 있습니다. 그러나 값을 선택하면 그리드를 다시로드하는 이벤트가 발생하지 않습니다 . 이 페이지에서 다음과 같이jQuery DataTables 미세 조정
<script type="text/javascript">
$(document).ready(function() {
<!-- Sorting and pagination -->
var oTable = $('#mainTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bFilter": false
});
<!-- Filtering -->
$("thead td").each(function(i) {
this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i));
$('select', this).change(function() {
oTable.fnFilter($(this).val(), i);
});
});
});
</script>
이 또한 내가 jquery.dataTables.js의 바닥에이 기능을 추가 한 :이 페이지의 내 jQuery 코드입니다 http://datatables.net/examples/api/multi_filter_select.html
(function ($) {
/*
* Function: fnGetColumnData
* Purpose: Return an array of table values from a particular column.
* Returns: array string: 1d data array
* Inputs: object:oSettings - dataTable settings object. This is always the last argument past to the function
* int:iColumn - the id of the column to extract the data from
* bool:bUnique - optional - if set to false duplicated values are not filtered out
* bool:bFiltered - optional - if set to false all the table data is used (not only the filtered)
* bool:bIgnoreEmpty - optional - if set to false empty values are not filtered from the result array
* Author: Benedikt Forchhammer <b.forchhammer /AT\ mind2.de>
*/
$.fn.dataTableExt.oApi.fnGetColumnData = function (oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty) {
// check that we have a column id
if (typeof iColumn == "undefined") return new Array();
// by default we only wany unique data
if (typeof bUnique == "undefined") bUnique = true;
// by default we do want to only look at filtered data
if (typeof bFiltered == "undefined") bFiltered = true;
// by default we do not wany to include empty values
if (typeof bIgnoreEmpty == "undefined") bIgnoreEmpty = true;
// list of rows which we're going to loop through
var aiRows;
// use only filtered rows
if (bFiltered == true) aiRows = oSettings.aiDisplay;
// use all rows
else aiRows = oSettings.aiDisplayMaster; // all row numbers
// set up data array
var asResultData = new Array();
for (var i = 0, c = aiRows.length; i < c; i++) {
iRow = aiRows[i];
var aData = this.fnGetData(iRow);
var sValue = aData[iColumn];
// ignore empty values?
if (bIgnoreEmpty == true && sValue.length == 0) continue;
// ignore unique values?
else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
// else push the value onto the result data array
else asResultData.push(sValue);
}
return asResultData;
}
} (jQuery));
function fnCreateSelect(aData) {
var r = '<select><option value=""></option>', i, iLen = aData.length;
for (i = 0; i < iLen; i++) {
r += '<option value="' + aData[i] + '">' + aData[i] + '</option>';
}
return r + '</select>';
}
내가 설정 fnFilter에서 중단 점을 지정하고 필터 드롭 다운 상자 중 하나의 값을 변경하면 중단 점은 적중하지 않지만 fnCreateSelect에서 설정하면 충돌이 발생합니다. 내가 뭔가 잘못하고 있는거야?
미리 감사드립니다.
편집 :
내가 사용하는 경우 :
이1 var oTable = $('#mainTable').dataTable({
2 "oLanguage": {
3 "sSearch": "Search all columns:"
4 },
5 "bJQueryUI": true,
6 "sPaginationType": "full_numbers",
7 "bFilter": false
8 });
.. 매김이 작동하지 않습니다,하지만 난 라인 2-4을 떠날 경우 필터링이 작동하지 않습니다. 아! 어떤 생각, 누구? 뷰어?
감사합니다,하지만 내 프로그램이 fnFilter 기능을 타격하지 않는 것처럼 보인다. 귀하의 코드를 추가하려했지만 아무 소용이 없습니다. 다시 한번 감사드립니다. 음악은 단결! –