jqxDropDownList Filter on Part of String - filtering

When jqxDropDownList, is there a way to enable filtering on any word in string. For example, if a value in the list is John Smith, I would like to be able to type "Smith" in the filter text and find this one.
I am setting the filterable setting to true, is there something else I can do to enable partial string filtering?

Looking into the javascript for the control, there are several settings that are not in the documentation, one of them is searchMode, which has values of:
containsignorecase
contains
equals
equalsignorecase
startswith
startswithignorecase
endswith
endswithignorecase
An example would be:
$("#jqxProductList").jqxDropDownList({
filterable: true,
searchMode: "containsignorecase",
checkboxes: true,
source: dataAdapter,
displayMember: "model",
valueMember: "product",
width: 400,
height: 25
});

Related

Ag-grid valueFormatter and Column Filter

I am having problems using ag-grid valueFormatter and column filters (https://www.ag-grid.com/javascript-data-grid/filtering/).
I have a simple colDef:
{
headerName: 'My column',
field: 'myData',
hide: true,
valueFormatter: this.formatterBooleanToHuman,
},
the formatterBooleanToHuman is a simple code to change true to Yes and false to No.
It works as expected, the issue is that we are using column filters, and when I click on the filter I have true and false to select, if I select any of them, nothing returns from the filters because the value now is actually Yes and No.
I couldn't manage to have both of them working together. To have the column filter working properly I need to remove the valueFormatter, but I would like to have both working.
I tried to apply the valueFormatter function to filterParams.valueFormatter, it did change the values on the filter but something is failing, I am getting 2 No and 1 Yes, and none of them filter.
Any suggestions?
UPDATE:
So, I found a solution, but I am not convinced it is the right way to do it.
get getcolumnDef(): Array<ColDef> {
return [
{
headerName: 'Boolean Column',
field: 'booleanValue',
hide: true,
valueFormatter: this.formatterBooleanToHuman,
filterParams: {
valueGetter: (params) => this.filterBooleanValueGetter(params, 'booleanValue')
}
}
];
}
private filterBooleanValueGetter(params: ValueGetterParams, propertyName: string) {
let isDeleted = false;
const hasValue = !!params && !!params.data && params.data[propertyName];
if (hasValue) {
isDeleted = String(params.data[propertyName]) === 'true';
}
return isDeleted ? 'Yes' : 'No';
}
So, the valueGetter works as expected and makes my filter work, I just think it is a bit "dirty" to have it to work like that, I haven't found anything on the docs saying this is the way it needs to be done. So suggestions are more than welcome.
valueFormatter applies only to data in grid. However even if the filter shows true and false instead of formatted values, it should work correctly. If filtering does not work, it may indicate some other error in your code. Maybe you depend on this in formatterBooleanToHuman method?
Anyway to format values in filter, you should define filterParams.valueFormatter like this:
{
// ...
valueFormatter: this.formatterBooleanToHuman,
filterParams: {
valueFormatter: this.formatterBooleanToHuman
}
}
For some reason, the value given to filter formatter is string instead of boolean (bug in ag-grid?), you need to adjust that.
See complete example here: https://plnkr.co/edit/o3sN3GodqQumVe09

How to filter an array of object in Mui DataGrid?

I recently changed my tables to Mui-datagrid on Material UI 5, and I have a special use case with an array of objects. I want to enable the phone number filter in this column, but the number is provided as an object list.
phone: [
{ type: "home", number: "795-946-1806" },
{ type: "mobile", number: "850-781-8104" }
]
I was expecting a 'customFilterAndSearch' or an option to customise how to search in this specific field.
customFilterAndSearch: (term, rowData) =>
!!rowData?.suppressedOptions.find(({ description }) =>
description?.toLowerCase().includes(term.toLowerCase())
),
I have made some tries with the filterOperators, but no success yet. I have made a full example here https://codesandbox.io/s/mui-data-grid-vs05fr?file=/demo.js
As far as I can see from the DataGrid documentation I don't see any way to change the filter function for a specific function.
Likely the best workaround for your use case will be converting this to a string be converting the data to a string before you pass it to the datagrid. Though you will lose the styling that you currently do by making the phone type bold.
On second though your best best would probably be to split the phone column into two columns which would probably be the cleanest way of solving your problem
Add helper function.
You could potentially add a helper function to just map all the phone lists to something like mobilePhone or homePhone
const mapPhoneObject = (rows) => {
rows.forEach((row) => {
row.phone.forEach((phone) => {
row[`${phone.type}Phone`] = phone.number;
});
});
return rows
};
I've added a fork of your snippet with my function, it is I think the most viable solution for your problem: https://codesandbox.io/s/mui-data-grid-forked-ppii8y

Ag-Grid Server Side Row Group Key Creator

When using Ag-Grid's server side row model, I am unable to send a custom group key to the server in order to do proper group by queries.
My row data is a simple JSON structure but with one composite object.
row = {
athlete: '',
age: '',
country: {
name: 'Ireland',
code: 'IRE'
},
...
}
I am using the server side row model. To get the grid to display the country name is simple enough as I use the following column definition.
{
headerName: "Country",
colId: "country",
valueGetter: "data.country.name",
enableRowGroup: true
}
However, when I group by the Country column ag-grid sends the groupKey as 'Ireland' from my example above. But I need the group key to be the country code, 'IRE'. I cannot figure out how to generate a groupKey when using the server-side row model.
I have seen the keyCreator method, but this only works for client-side row model. In addition, I have seen the Tree Data Mode which has a callback for getServerSideGroupKey(dataItem) but then callback only gets used when gridOptions.treeData = true and when the treeData option is set to true, a "Group" column is always displayed regardless if a grouping is happening or not. I tested this out by setting isServerSideGroup: function(dataItem) {return false;}
Any help would be appreciated.
I was able to solve this issue by using the dot notation for the column definition's field attribute and a custom cellRenderer.
{
headerName: "Country",
colId: "country",
field: "country.code",
enableRowGroup: true,
cellRenderer: function (params) {
return params.data.country.name;
}
}
This allowed me to display the correct data point from the custom object and when doing server side actions, ag-grid will send the datapoint contained within the field attribute.

ag-grid enterprise server side how to set agSetColumnFilter filter checkboxes

I am using ag-grid enterprise 20.2 using server side and have a column where I would like to use the agSetColumnFilter filter type. The column and filter display fine, but when I go to check a filter checkbox it returns from filterModel empty and no checkboxes are changed.
{
headerName: 'header,
field: 'field',
width: 150,
filter: 'agSetColumnFilter',
filterParams: {
values: (valuesParams) => {
const values = Object.entries(field_values).map(e => e[1].id);
valuesParams.success(values);
},
},
},
I am guessing that there is a callback or something to update the filter (setModel?), but I have not been able to sort out what the API is. Could someone let me know how to do this?
This looks to be a bug in the software. I changed to rowModelType="infinite" leaving almost everything else the same and it now works.

Azure DevOps REST API - How are Picklists associated with Field?

I am trying to use rest to create fields and picklists, on the web site I created a field as type picklist String and added some items to the list:
Rest url for field:
https://dev.azure.com/{org}/_apis/work/processes/{processId}/workitemtypes/CMMI2.Bug/fields/Custom.AppType?api-version=5.0-preview.2
it is returning this:
{
referenceName: "Custom.AppType",
name: "AppType",
type: "string",
description: "",
url: "https://dev.azure.com/{org}/_apis/work/processes/bd96307e-3d16-44ac-b498-be1a8daff2d5/behaviors",
customization: "custom"
}
Rest URL for picklist:
https://dev.azure.com/{org}/_apis/work/processes/lists/{picklistId}?api-version=5.0-preview.1
this returns:
{
items: [
"All",
"Item2",
"Item3"
],
id: "{picklistId}",
name: "picklist_{diffGuidFromPickListId}",
type: "String",
isSuggested: false,
url: "https://dev.azure.com/{org}/_apis/work/processes/lists/{picklistId}"
}
Here is documentation for this:
https://learn.microsoft.com/zh-cn/rest/api/azure/devops/processes/fields/get?view=azure-devops-rest-5.0#processworkitemtypefield
Firstly - why is type of field string when it should be picklistString (as per documentation link)?
Secondly - how is the picklist linked to the field?
thanks
The picklistString refers to the name of the type, its actual property is string, so the field type it displays in type is string.
Secondly - how is the picklist linked to the field?
(1) To achieve this, you can use this API:
POST https://dev.azure.com/{organizationName}/{projectName}/_apis/wit/fields?api-version=5.1-preview.2
Here is my request body for you reference:
{
  "name": "{FieldName}",
  "referenceName": "{the reference name of WIT},
  "type": "string",
  "usage": "workItem",
  "readOnly": false,
  "canSortBy": true,
  "isQueryable": true,
  "supportedOperations": [
    {
      "referenceName": "{the reference name of WIT}"
      "name": "="
    }
  ],
  "isIdentity": true,
  "isPicklist": true,
  "isPicklistSuggested": false,
  "url": null
}
Note: Set isPicklist as true, and you can link picklist to this new field.
(2) For UI operation, just add new field, open the drop-down list of type and select picklist(string)/picklist(Integer) as what you need.
The difference between picklist(string) and picklist(Integer) is that picklist(string) allow a pick list of short text string (255 characters or less) values, and picklist(Integer) contains a pick list of Integer values.
It would appear that this is all moot, since the picklistId property cannot be changed once it has been set (i.e. at field creation).
In this reference material, picklistId has "No" as its value for the "Can change?" column: https://learn.microsoft.com/en-us/azure/devops/boards/work-items/work-item-fields?view=azure-devops