Grid Column Custom Operator List

0 Answers 24 Views
Filter Grid
Curtis
Top achievements
Rank 1
Curtis asked on 18 Nov 2023, 08:59 PM

I'm trying to determine how to specify a custom list of operators for a specific column using the JSP grid. The documentation isn't helping, as it just states that it's the same configuration as for Jquery - https://docs.telerik.com/kendo-ui/api/jsp/grid/column-filterable#operators

I've tried to enter in a JSON string, but it's not working:

<kendo:grid-column-filterable operators="enums: {
		eq: 'Equal to',
		neq: 'Not equal to',
		contains: 'Contains',
		doesnotcontain: 'Does Not Contain',
		isnotempty: 'Is not empty',
		isempty: 'Is empty'
	}"
>

If I could just see an example of what it should look like I could take it from there. Alternatively, I wouldn't mind trying to configure a new data type for the column specifically, but that's unfortunately not working either.

$(document).ready(function() {
    kendo.ui.FilterMenu.fn.options.operators.objectCollection = {
  	      eq: "Equal to",
  	      neq: "Not equal to",
  	      contains: "Contains",
  	      doesnotcontain: "Does Not Contain",
  	      isnotempty: "Is not empty",
  	      isempty: "Is empty"
    };
    kendo.ui.Filter.fn.options.operators.objectCollection = {
		  eq: "Equal to",
		  neq: "Not equal to",
		  contains: "Contains",
		  doesnotcontain: "Does Not Contain",
		  isnotempty: "Is not empty",
		  isempty: "Is empty"
    };
});
<kendo:dataSource-schema-model-field name="pivotedCollectionColumn" type="objectCollection"/>

 

To clarify, my use case is the display of a collection of objects. A mapping table of ManyToMany. My grid displays the parent as a single record, so my column is keyed to a special field that is performing pivoting of the collection values for a comma-delimited single-row display: "value1, value2, value3". I have everything working server-side for my filtering, accounting for the proper collection de-referencing. It's just a matter of the "enums" type that I'm currently using only has eq, neq, isnull, and isnotnull. I need the operators I've shown previously. Even currently, my server-side code is converting the null operators to empty operators, since those are what I actually utilize.

Nikolay
Telerik team
commented on 22 Nov 2023, 03:21 PM

Hi Curtis,

You can use the <kendo:grid-filterable-operators> tag to update the operators text:

As a side note, I would like to inform you that as of 1st of December 2023, we are deprecating Telerik UI for JSP. More about the reason for this and how is it affecting you please find at the below link:

Regards,

Nikolay

Curtis
Top achievements
Rank 1
commented on 22 Nov 2023, 11:21 PM

Okay, migrating to deal with the deprecation is on my priority list.

But in the meantime, I'm not sure if that's the answer I'm looking for. Aren't those tags just for localization of the filters? And it doesn't appear that those can apply to a singular column.

I have several enums columns that I want to keep the standard filters for. For just one particular column, I want the filter operators to be [eq, neq, contains, doesnotcontain, isnotempty, isempty]. I'm fine with the default localizations, I'm just looking for a customized list of filter operators.

If I'm misunderstanding and these tags will provide a customized list of operators for a singular column, could you please provide a simple example of what the configuration would look like? I love the JQuery documentation, because it always provides examples which help me understand exactly what a bit of configuration does and how it should be written. The JSP documentation you linked doesn't show simple usages.

Nikolay
Telerik team
commented on 27 Nov 2023, 11:42 AM

Hi Curtis,

Thank you for the follow-up.

The custom operator column list should look something like the following:

<%
object[] customOperators = new Object[]{"eq": "equals"};
%>
<kendo:grid-column-filterable operators="<%= customOperators %>"></kendo:grid-column-filterable>

Or:

<%
object[] customOperators = new Object[]{"eq": "equals"};
%>
<kendo:grid-column-filterable operators="customOperators"></kendo:grid-column-filterable>

Alternatively, you can always invoke the setOptions() method after the Grid is initialized and pass to it the desired options configurations:

      var grid = $("#grid").data("kendoGrid");
      var columns = grid.columns;
      columns[0].filterable.operators.string = {
        eq: "custom equal",
        neq: "custom not equal"
      };

      grid.setOptions({
        columns: columns
      });

Dojo demo: https://dojo.telerik.com/eZEfUzUC

Regards,

Nikolay

 

 

Curtis
Top achievements
Rank 1
commented on 05 Dec 2023, 11:11 PM

Thank you for the response. Unfortunately, what you provided for the JSP tags doesn't work. We can't define an array of objects as a JSON object is Java. The code fails, obviously.

I attempted to take the basic logic and convert it to a hash map instead:

<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%
        Map<String, String> customOperators = new HashMap<String, String>();
	customOperators.put("eq", "Equal to");
	customOperators.put("neq", "Not equal to");
	customOperators.put("contains", "Contains");
	customOperators.put("doesnotcontain", "Does Not Contain");
	customOperators.put("isnotempty", "Is not empty");
	customOperators.put("isempty", "Is empty");
%>
..............
<kendo:grid-column-filterable operators="customOperators">

Unfortunately, this fails. The kendo JS code isn't able to parse things. Here is the console error I receive:

kendo.all.min.js:9 
 Uncaught TypeError: Cannot read properties of undefined (reading 'eq')
    at init.<anonymous> (kendo.all.min.js:9:1099160)
    at init.trigger (kendo.all.min.js:9:2618)
    at init.set (kendo.all.min.js:9:81962)
    at init._refreshUI (kendo.all.min.js:9:1100291)
    at new init (kendo.all.min.js:9:1097402)
    at HTMLSpanElement.<anonymous> (kendo.all.min.js:9:39777)
    at Function.each (jquery-2.2.4.js:365:19)
    at Te.fn.init.each (jquery-2.2.4.js:137:17)
    at t.fn.<computed> [as kendoFilterCell] (kendo.all.min.js:9:39753)
    at init._filterRow (kendo.all.min.js:9:1330840)
(anonymous)	@	kendo.all.min.js:9
trigger	@	kendo.all.min.js:9
set	@	kendo.all.min.js:9
_refreshUI	@	kendo.all.min.js:9
init	@	kendo.all.min.js:9
(anonymous)	@	kendo.all.min.js:9
each	@	jquery-2.2.4.js:365
each	@	jquery-2.2.4.js:137
t.fn.<computed>	@	kendo.all.min.js:9
_filterRow	@	kendo.all.min.js:9
_thead	@	kendo.all.min.js:9
_continueInit	@	kendo.all.min.js:9
init	@	kendo.all.min.js:9
(anonymous)	@	kendo.all.min.js:9
each	@	jquery-2.2.4.js:365
each	@	jquery-2.2.4.js:137
t.fn.<computed>	@	kendo.all.min.js:9
(anonymous)	@	index:618
fire	@	jquery-2.2.4.js:3187
fireWith	@	jquery-2.2.4.js:3317
ready	@	jquery-2.2.4.js:3536
completed	@	jquery-2.2.4.js:3552
Unfortunately, I don't believe the map is even being passed in correctly. If I change the map to only populate "neq", it still references "eq" in the console error.
Nikolay
Telerik team
commented on 08 Dec 2023, 02:44 PM

HI Curtis,

Just to let you know I need more time to investigate. I will follwo up shortly.

Regards,

Nikolay

Curtis
Top achievements
Rank 1
commented on 14 Dec 2023, 11:58 PM

Hello again. Just wanted to know if anything has come up?
Nikolay
Telerik team
commented on 19 Dec 2023, 12:56 PM

Hi Curtis,

Please accept my apologies for the delayed reply.

I am not sure why is this not accepted. Did you try the setOptions() option I mentioned previously?

Furthermore, we have deprecated Telerik UI for JSP since the 1st of December 2023.  More about this you can find in the below article:

Regards,

Nikolay

No answers yet. Maybe you can help?

Tags
Filter Grid
Asked by
Curtis
Top achievements
Rank 1
Share this question
or