SAPUI5 in-table search (Uncaught Error: Only "String" values are supported for the FilterOperator: "Contains".)

SAPUI5 in-table search (Uncaught Error: Only "String" values are supported for the FilterOperator: "Contains".)

我有一个 SAPUI5 table,其中包含字符串值数据(例如名称)和整数数据(例如 ID)。当我对字符串使用 in-table 搜索选项时,它工作得很好。

当我尝试搜索 ID 的一部分时,出现以下错误:

(Uncaught Error: Only "String" values are supported for the FilterOperator: "Contains".)

我想像搜索字符串一样搜索我的整数

尝试 1:

var oTextView = new sap.ui.commons.TextView( {
            text : {
                path : "id",
                formatter : function(oContext) {
                    if (oContext) {
                        return oContext.toString();
                    } else
                        return;
                }
                }
            });

尝试 2:

var oTextView = new sap.ui.commons.TextView( {
            text : {
                path : "id",
                type : new sap.ui.model.type.String(),
                }
            });

尝试 3:

结合以前的尝试(结果是我无法打开 in-table 搜索此列):

oColumn.setFilterProperty(sap.ui.model.type.String())
oColumn.setSortProperty(new sap.ui.model.type.String())

编辑:view/controller

view:

var oTable = new sap.ui.table.Table();
oTable.setModel(sap.ui.getCore().getModel("myModel"));
oTable.bindRows("/myPath");

var oTextView = new sap.ui.commons.TextView();
            oTextView.bindProperty("text", "myProperty");

var oColumn =   var oColumn = new sap.ui.table.Column({
label : new sap.ui.commons.Label( {
                text : "My Column"
            }),
            template : oTextView,
            sortProperty : "myProperty",
            filterProperty : "myProperty",
});
oTable.addColumn(oColumn);

Controller:

var oModel = new sap.ui.model.json.JSONModel(MyData); 
sap.ui.getCore().setModel(oModel, "myModel");

尝试使用:

var oTextView = new sap.ui.commons.TextView( {
    text : "" + "{id}" + ""
});

这样你的整数将作为字符串给出

我遇到了同样的问题,转换为字符串解决了这个问题。但是我会提交错误报告,因为过滤器也应该与数字一起使用。特别是因为排序仅按预期对数字进行。作为解决方法,我执行了以下操作:

  1. 通过以下方式转换为字符串:var my_string = my_num.toString(); 这似乎更好,然后通过上面提出的连接进行隐式转换。
  2. 在过滤器的绑定中使用字符串值
  3. 使用绑定中的数字值进行排序

这是一些伪代码,因为有人要求它。字符串值只添加到模型中进行排序:

var your_data_model = [{int_value = 111},{int_value=222}];
your_data_model[0].string_value = "111"; //add a string value for filter
your_data_model[1].string_value = "222"; //add a string value for filter

//in your table object add the sorting as usal on the column level
var oColumn = new sap.ui.table.Column({
    label : oLabel,
    template : oObject
});
oColumn.setSortProperty("int_value"); //sort well for numbers
oColumn.setFilterProperty("string_value"); //filter worlds for string