我有jqGrid和客户端过滤。我有一列id_medpred
,其中包含相关表的外键,但显示来自相关表name
的相应字符串字段medpreds
。
我想要:在该列的过滤器工具栏中按字符串字段name
进行搜索,但我不知道该怎么办。此时,过滤器仅由外键的整数值起作用。网格初始化:
$("#table-extrefs").jqGrid({
editurl: 'test.php',
datatype: 'clientSide',
rowNum: 9999,
loadonce: true,
cellEdit: true,
cellsubmit: 'remote',
cellurl: 'index.php?article=external_referers&act=process_submit',
colNames: [
'ФИО врача',
'Код врача',
'Дата добавления',
'Специальность',
'Телефон',
'Медпред',
'Медпред',
'ЛПУ',
],
colModel: [
{name: 'id', index: 'id', hidden: true, key: true},
{name: 'fio', index: 'fio', width: '200', sortable: true, sorttype: 'text', editable: true, edittype: "text", frozen: true},
{name: 'code', index: 'code', width: '55', sortable: true, sorttype: 'text', editable: true, edittype: "text", frozen: true},
{name: 'adding_date', formatter: 'date', index: 'adding_date', width: '65', sortable: true, sorttype: 'date', editable: false,
srcformat: 'dd.mm.YY', edittype: "text", frozen: true,
searchoptions: {
searchOperators: true,
sopt: ['ge'],
clearSearch: false,
dataInit: function (elem) {
$(elem).datepicker({
dateFormat: 'dd.mm.yy',
autoSize: true,
language: 'ru',
changeYear: true,
changeMonth: true,
showButtonPanel: true,
showWeek: true
});
}
}
},
{name: 'speciality', index: 'speciality', sortable: true, width: '95', editable: true, edittype: "text", frozen: true},
{name: 'phone', index: 'phone', editable: true, edittype: "text", width: '90', frozen: true},
{name: 'id_medpred', index: 'id_medpred', sortable: true, editable: true,
edittype: 'select',
formatter: 'select',
editoptions: {value: getAllMedpreds()},
frozen: true,
width: '100',
//searchrules : { custom_func : function(a,b){ console.log(a,b);}}
},
{name: 'medpred', index: 'medpred', sortable: true, editable: true, edittype: "text", frozen: true, hidden: true, },
{name: 'lpu', index: 'lpu', sortable: true, editable: true, edittype: "text", frozen: true},
{name: 'metro', index: 'metro', sortable: true, editable: true, edittype: "text", width: '150', frozen: true},
{name: 'district', index: 'district', editable: true, edittype: "text", width: '50', frozen: true},
],
forceFit: true,
ignoreCase: true,
height: '630px',
width: '1200px',
viewrecords: true,
});
修改
感谢Tony Tomow。
我做了一些非常丑陋的解决方案,但确实有效:
beforeSearch : function() {
//gs_id_medpred it's id of filter input field.
var medpred = $('#gs_id_medpred').val();
var medpreds = getAllMedpreds()
var filters = $('#table-extrefs').getGridParam("postData").filters;
if ("undefined" != typeof(medpred) && medpred.length > 0)
{
filters_obj = JSON.parse(filters);
for (var i in filters_obj.rules)
{
if (filters_obj.rules[i].field === 'id_medpred')
{
for (var j in medpreds)
{
if (medpreds[j].indexOf(medpred)!==-1)
{
filters_obj.rules[i].data = j;
break;
}
}
}
}
$('#table-extrefs').getGridParam("postData").filters = JSON.stringify(filters_obj);
var filters = $('#table-extrefs').getGridParam("postData").filters;
console.log(filters);
}
我处理了之前的搜索,并在medpreds
字典中相应地更改了过滤数据。
答案 0 :(得分:1)
首先阅读我看到两种可能的解决方案
将select2 plugin用于选择元素
定义与medpreds名称相对应的隐藏字段,但将其设置为可搜索(如果使用搜索对话框,则会出现这种情况)这种方式在搜索对话框中将出现名称,您可以在其上搜索
{name:“medspredname”,hidden:true,... searchoptions:{searchhidden:true} ...}