Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript DataTables sAjaxSource Json higlight搜索数据_Javascript_Jquery_Ajax_Json_Jquery Datatables - Fatal编程技术网

Javascript DataTables sAjaxSource Json higlight搜索数据

Javascript DataTables sAjaxSource Json higlight搜索数据,javascript,jquery,ajax,json,jquery-datatables,Javascript,Jquery,Ajax,Json,Jquery Datatables,我正在尝试在数据表上实现搜索突出显示(JSON数据即将到来,并通过“sAjaxSource”从服务器端填充该表),有关详细信息,请参阅下面的代码 默认情况下,搜索工作正常,但高亮显示根本不工作 我提醒了searchTxt+=$('search_input').val()的数据;警报(“txt”+searchTxt); 警报显示搜索输入框文本。 “警报(“+aData[j]);“显示”未定义而非列数据和突出显示的警报不起作用。 有人能解释一下吗 谢谢,, 斯里兰卡 jQuery(文档).ready

我正在尝试在数据表上实现搜索突出显示(JSON数据即将到来,并通过“sAjaxSource”从服务器端填充该表),有关详细信息,请参阅下面的代码

默认情况下,搜索工作正常,但高亮显示根本不工作

我提醒了searchTxt+=$('search_input').val()的数据;警报(“txt”+searchTxt); 警报显示搜索输入框文本。 “警报(“+aData[j]);“显示”未定义而非列数据和突出显示的警报不起作用。

有人能解释一下吗

谢谢,, 斯里兰卡

jQuery(文档).ready(函数(){
var-oTable=jQuery(“#示例”).dataTable({
“sDom”:“tipl”,
“sAjaxSource”:ajaxURL,
“bDeferRender”:没错,
“bProcessing”:正确,
“bJQueryUI”:没错,
“sScrollY”:500,
“aaSorting”:[[0,'说明']],
“aoColumns”:[
{“mData”:“name”},
{“mData”:“flag”}
],
“oSearch”:{“sSearch”:“,
“bSmart”:没错,
“bRegex”:false},
“sPaginationType”:“分页”,
“fnRowCallback”:函数(nRow、aData、iDisplayIndex、iDisplayIndexFull){
$(nRow).addClass('clickable');
$(nRow).attr('onClick',“editPopup”(+aData['conditionId']+”);
},
“fnDrawCallback”:函数(oSettings){
美元(美元);
}
});
$(“#示例#过滤器标签”).attr(“for”,“search#u输入”);
$(“#示例_过滤器输入”).attr({
“id”:“搜索输入”,
“占位符”:“搜索”
}); 
oTable.fnSearchHighlighting();
});
jQuery.fn.dataTableExt.oApi.fnSearchHighlighting=函数(oSettings){
oSettings.oPreviousSearch.oSearchCaches={};
oSettings.oApi.\u fnCallbackReg(oSettings,'aoRowCallback',函数(nRow,aData,iDisplayIndex,iDisplayIndexFull){
var searchStrings=[];
var oApi=this.oApi;
var cache=oSettings.oPreviousSearch.oSearchCaches;
//全局搜索字符串
//如果存在全局搜索字符串,请将其添加到搜索字符串数组中
if(oSettings.oPreviousSearch.sSearch){
searchStrings.push(oSettings.oPreviousSearch.sSearch);
}
//单个列搜索选项对象
//如果存在单个列搜索字符串,请将它们添加到搜索字符串数组中
searchTxt=$('#filter_input[type=“text”]')。val();
searchTxt+=$(“#搜索输入”).val();
警报(“txt”+searchTxt);
if((oSettings.aoPreSearchCols)和&(oSettings.aoPreSearchCols.length>0)){
for(oSettings.aopresarchcols中的变量i){
if(oSettings.aoPreSearchCols[i].sSearch){
searchStrings.push(searchTxt);
}
}
}
//根据需要创建从一个或多个搜索字符串和缓存生成的正则表达式
如果(searchStrings.length>0){
var sSregex=searchStrings.join(“|”);
如果(!缓存[sSregex]){
//此正则表达式将避免在HTML匹配中使用
cache[sSregex]=newregexp(“(“+escapeRegExpSpecialChars(sSregex)+”(!([^)”,“i”);
}
var regex=cache[sSregex];
}
//在行/字段中循环查找匹配项
jQuery('td',nRow).每个(函数(i){
//考虑到ColVis可能正在使用
var j=oApi.\u fn可见色谱柱指数(oSettings,i);
//仅当单元格不为空或null时才尝试突出显示
警报(“+aData[j]);
if(aData[j]){
//如果有搜索字符串,请尝试匹配
如果((sSregex的类型!==“未定义”)&&(sSregex)){
警报(“此处”);
this.innerHTML=aData[j].replace(正则表达式,函数(匹配){
返回“+匹配+”;
});
}
//否则重置为干净字符串
否则{
this.innerHTML=aData[j];
}
}
});
返回nRow;
}“行高亮显示”);
归还这个;
};

无论搜索功能在何处,如果使用mData填充json数据,请使用mData信息检索列数据并突出显示(不要使用索引检索列数据以进行搜索和突出显示)

var colProp=oSettings.aoColumns[i].mData;

    jQuery('td', nRow).each( function(i) {
                    /* Take into account that ColVis may be in use

                        var j = oApi._fnVisibleToColumnIndex( oSettings,i);

                    Only try to highlight if the cell is not empty or null
                     */
                    var colProp = oSettings.aoColumns[i].mData;

                if (aData[colProp] !== undefined && aData[colProp] !== null && aData[colProp] !== "") {
                        // If there is a search string try to match
                        if ((typeof sSregex !== 'undefined') && (sSregex)) {
                            var mapObj = {
                                            '®' : "\u00AE",
                                            '™' : "\u2122",
                                            '"'  : "\u201C",
                                            ' '  : " "
                                        };
                                        aData[colProp] = aData[colProp].replace(/(®)|(™)|(")|( )/gi, function(matched){
                                            return mapObj[matched];
                                        }); 
                            this.innerHTML = aData[colProp].replace( regex, function(matched) {
                                return "<span class='filterMatches'>"+matched+"</span>";
                            });
                        }

                        else {
                            this.innerHTML = aData[colProp];
                        }
                    }
                });
                return nRow;
            }, 'row-highlight');
            return this;
jQuery('td',nRow).每个函数(i){
/*考虑到ColVis可能正在使用
var j=oApi.\u fn可见色谱柱指数(oSettings,i);
仅当单元格不为空或null时才尝试突出显示
*/
var colProp=oSettings.aoColumns[i].mData;
if(aData[colProp]!==undefined&&aData[colProp]!==null&&aData[colProp]!==“”){
//如果有搜索字符串,请尝试匹配
如果((sSregex的类型!==“未定义”)&&(sSregex)){
var mapObj={
“®;”:“\u00AE”,
“™;”:“\u2122”,
“";”:“\u201C”,
' '  : " "
};
aData[colProp]=aData[colProp]。替换(/(®;)|(™;)|(";)|()/gi,函数(匹配){
返回mapObj[matched];
}); 
this.innerHTML=aData[colProp].replace(正则表达式,函数(匹配){
返回“+匹配+”;
});
}
否则{
this.innerHTML=aData[colProp];
}
}
});
返回nRow;
}“行高亮显示”);
归还这个;
    jQuery('td', nRow).each( function(i) {
                    /* Take into account that ColVis may be in use

                        var j = oApi._fnVisibleToColumnIndex( oSettings,i);

                    Only try to highlight if the cell is not empty or null
                     */
                    var colProp = oSettings.aoColumns[i].mData;

                if (aData[colProp] !== undefined && aData[colProp] !== null && aData[colProp] !== "") {
                        // If there is a search string try to match
                        if ((typeof sSregex !== 'undefined') && (sSregex)) {
                            var mapObj = {
                                            '&#0174;' : "\u00AE",
                                            '&#0153;' : "\u2122",
                                            '&#034;'  : "\u201C",
                                            '&nbsp;'  : " "
                                        };
                                        aData[colProp] = aData[colProp].replace(/(&#0174;)|(&#0153;)|(&#034;)|(&nbsp;)/gi, function(matched){
                                            return mapObj[matched];
                                        }); 
                            this.innerHTML = aData[colProp].replace( regex, function(matched) {
                                return "<span class='filterMatches'>"+matched+"</span>";
                            });
                        }

                        else {
                            this.innerHTML = aData[colProp];
                        }
                    }
                });
                return nRow;
            }, 'row-highlight');
            return this;