Yadcf - 服务器端多选

时间:2015-09-28 23:27:04

标签: datatables yadcf

我使用了yadcf multi_select函数 当我搜索两个单词时,该函数给我一个管道。我不知道如何删除它,因为他分别理解这两个词。

http://www.hostingpics.net/viewer.php?id=710742Capture.jpg

我发现管道将以此功能开始:



function doFilterMultiSelect(arg, table_selector_jq_friendly, column_number, filter_match_mode) {
		$.fn.dataTableExt.iApiIndex = oTablesIndex[table_selector_jq_friendly];
		var oTable = oTables[table_selector_jq_friendly],
			selected_values = $(arg).val(),
			selected_values_trimmed = [],
			i,
			stringForSearch,
			column_number_filter,
			settingsDt = getSettingsObjFromTable(oTable);

		column_number_filter = calcColumnNumberFilter(settingsDt, column_number, table_selector_jq_friendly);
		$(document).data("#yadcf-filter-" + table_selector_jq_friendly + "-" + column_number + "_val", selected_values);

		if (selected_values !== null) {
			for (i = selected_values.length - 1; i >= 0; i--) {
				if (selected_values[i] === "-1") {
					selected_values.splice(i, 1);
					break;
				}
			}
			for (i = 0; i < selected_values.length; i++) {
				selected_values_trimmed.push($.trim(selected_values[i]));
			}
			if (selected_values_trimmed.length !== 0) {
				stringForSearch = selected_values_trimmed.join('narutouzomaki');
				stringForSearch = stringForSearch.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
				stringForSearch = stringForSearch.split('narutouzomaki').join('|');
				if (filter_match_mode === "contains") {
					oTable.fnFilter(stringForSearch, column_number_filter, true, false, true);
				} else if (filter_match_mode === "exact") {
					oTable.fnFilter("^(" + stringForSearch + ")$", column_number_filter, true, false, true);
				} else if (filter_match_mode === "startsWith") {
					oTable.fnFilter("^(" + stringForSearch + ")", column_number_filter, true, false, true);
				} else if (filter_match_mode === "regex") {
					oTable.fnFilter(stringForSearch, column_number_filter, true, false, true);
				}
			} else {
				oTable.fnFilter("", column_number_filter);
			}
		} else {
			oTable.fnFilter("", column_number_filter);
		}
		resetIApiIndex();
	}
&#13;
&#13;
&#13;

我似乎无法解决操作multi_select的问题。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

由于您在某个列yadcf上使用多选过滤器,因此会将|(或)字符串发送到您的服务器。

在服务器端,您必须将字符串拆分为数组/字符串列表并构造正确的SQL查询。

Split in Java

Split in PHP(see code sample in bottom

p.s我是yadcf的作者