Extjs 7.2.0 - Remote Filtering problem with multiple filters on same field - extjs

I have an Ext grid and store. The store fields are
fields: ['id', {
name: 'name',
type: 'string'
}, {
name: 'dob',
type: 'date'
}]
The relevant grid column for date is set as
{
xtype: 'datecolumn',
dataIndex: 'dob',
text: 'Date of Birth',
format: 'd-m-Y',
filter: 'date'
}
Here, the filter attribute is for the gridfilters plugin.
I would also like to have the filters applied programmatically on the dob field like so -
store.filter([{
property: 'dob',
value: new '01/17/1990',
operators: 'gt'
},{
property: 'dob',
value: '01/17/2022',
operators: 'lt'
}])
However, although the gridfilter plugin works with multiple filters on the same field, programmatically this doesn't. It only applies the last filter from the array.
With the gridfilter plugin, I get multiple filters like -
[
{
"property": "dob",
"operator": "lt",
"value": "18/01/1990"
},
{
"property": "dob",
"operator": "gt",
"value": "18/01/2022"
}
]
However, when I try it programmatically, I only get -
[
{
"property": "dob",
"operator": "gt",
"value": "18/01/2022"
}
]
Any suggestions toward this will be very helpful.
I've created a Sencha Fiddle to demonstrate the issue.
Sencha Fiddle

You can add multiple filters for the same property by setting a different id property for the filters. Change this in your code:
if (from && to){
var filters = [{
id: 1,
property: 'dob',
operator: 'gt',
value: from
},{
id: 2,
property: 'dob',
operator: 'lt',
value: to
}]
store.filter(filters);
}
If you change it in your fiddle, under Filters Applied you will see that both filters are set this way. Anyway, I think you need to adjust this a bit to actually work, because your dates are stored currently as text.

Related

Unable to layout composite field items

I am using Ext JS 3.4 and in the composite field, there are three fields, code is as below:
xtype: 'compositefield',
name: 'comboField',
fieldLabel: 'Partner with',
width: 400,
cItems:[{
xtype: 'combo',
name: 'partnerTypeCombo',
value: 'ProviderName',
mode: 'local',
store: new Ext.data.ArrayStore({
fields: ['id', 'displayValue'],
data: [
['ProviderName', 'Provider Partner Name'],
['OtherProvider', 'Other Provider Partner']
]
}),
valueField: 'id',
displayField: 'displayValue',
listeners: {
scope: this,
select: function(combo, record, index) {
var providerField = this.formPanel.getForm().findField('comboField_providerPartnerNameField');
var otherProviderField = this.formPanel.getForm().findField('comboField_otherProviderPartnerNameField');
if (combo.value == "OtherProvider") {
providerField.setVisible(false);
otherProviderField.setVisible(true);
}
else {
providerField.setVisible(true);
otherProviderField.setVisible(false);
}
}
}
}, {
xtype: 'spacer',
width: 10,
flex: 0
}, {
xtype: 'modellinkfield',
name: 'providerPartnerNameField',
modelLevelType: 'Organization',
modelType: 'Organization',
pickerReport: {
reportName: 'TMS.SupplierVendorOrgPicker',
targetLevelType: 'Organization'
}
}, {
xtype: 'textfield',
name: 'otherProviderPartnerNameField',
hidden: true
}]
By using the above code and without hiding any field, I got the below result
But My expectation is
By default third field (which is text field) should be hidden
On selecting Combobox values, the next two fields should be visible/hidden.
Like if dropdown field value is "Provider Partner Name" then only second
field (modeling field) should be visible (shown as below)
And if dropdown field value is "Other Provider Name" then only third
field (i.e text field) should be visible.
But I am unable to achieve this third objective. I am getting the following output for this (the field is getting overridden)
And I am expecting the following output.
Looks like this may be some layout issue or maybe I need to apply some CSS style to handle this. Can someone please help me to solve this issue.
Able to solve this issue by using below code :
otherProviderField.ownerCt.doLayout();

uigrid remove initial blank option from dropdown filter

Here's the screenshot of my ui-grid.
Here's the code that creates that filter.
{ field: 'channel_type', displayName: "Type", filter: {
type: uiGridConstants.filter.SELECT,
selectOptions: [
{ value: 'HD', label: 'HD' },
{ value: 'SD', label: 'SD' }
]
}},
{ field: 'price', displayName: "Price", enableFiltering: false, enableSorting: false},
My data is loaded in uigrid from rest api call.
I really can't figure it out from where is it adding that blank option. I haven't found any solution to this issue. Please help me in solving this problem.
Its a known issue, see ui-grid issues
The solution (workaround) is to add some custom style:
#grid1 div div select option:first-child[value=""] {
display: none;
}
Demo Plunker
You have to use filterHeaderTemplate and create your dropdown in it. Here is the example:
field: 'yourField',
filterHeaderTemplate: '<div class="ui-grid-filter-container" ng-repeat="colFilter in col.filters"><select class="grid-filter-control" ng-model="colFilter.term" ng-options="option.value as option.label for option in colFilter.selectOptions"></select></div>',
filter: {
disableCancelFilterButton: true,
term: '',
type: uiGridConstants.filter.SELECT,
selectOptions: [{ value: '', label: 'All' },
{ value: '1', label: 'Something' },
{ value: '2', label: 'Something Else' }]
}
Defining term will select your first option and the empty one is not going to show.

Binding Grid and Form ExtJs 6

I have a grid populating records from view model (Ajax proxy data from Java restful web services). When I select a record in the grid form open and the fields are displayed. The records are editable using the form.
I have one tag field which is binded to a store and I should be able to populate the data associated to the record whenever the user selects a record.
"data" : [ {
"createdOn" : 1475678859000,
"updatedOn" : 1475679885000,
"updatedBy" : null,
"id" : 174,
"userName" : "ffff,
"firstName" : "gg",
"lastName" : "ggg",
"salesDepartment" : [ {
"id" : 3,
"code" : "FC",
"name" : "Fiat-Chrysler",
"departmentHead" : "xxx",
"applicationCode" : null} ],}
I need to bind the value of id from sales department object . how can I achieve this. Please help me.
{xtype: 'tagfield',
anchor: '100%',
reference: 'salesDept',
fieldLabel: 'Sales Dept\'s',
name: 'salesDepartment',
allowBlank: false,
displayField: 'name',
valueField: 'id',
bind: {
value: '{record.salesDepartmentIds}',
store: '{SalesDepartmentStore}'},
}
Tag fields are really only designed to work with arrays or comma separated lists;
It looks like you are trying to use with associations, which it would be nice if there was more support for this out of the box.
I've had a go, and in terms of displaying got it working however saving values will really depend on how you plan to sync values to the server, if you are going to use in built proxies etc. then this will present a whole different challenge. I would like a similar component for my own apps, I will think on this further and may even create a UX for this.
I think you have several issues here, one is getting your associations working properly, then you need to make your tagfield work as expected.
Here is the fiddle
And the key parts are:
An extended tagfield:
Ext.define('RelatedTagField', {
extend: 'Ext.form.field.Tag',
xtype: 'rtagfield',
config: {
relatedStore: null
},
setValue: function (val) {
this.setRelatedStore(val);
var value;
if (val && val.isStore) {
value = val.collect('id');
} else {
value = '';
}
this.callParent([value]);
},
getValue: function () {
return this.relatedStore;
},
onBindStore: function () {
this.callParent(arguments);
this.on('select', function (tagfield, selection) {
var selectedIds = [];
//add any new selections
Ext.each(selection, function (rec) {
var rrec = this.relatedStore.getById(rec.id);
if (!rrec) {
this.relatedStore.add(rec.data)
}
selectedIds.push(rec.id);
}, this);
//remove any not selected anymore
this.relatedStore.each(function (rrec) {
if (selectedIds.indexOf(rrec.id) == -1) {
this.relatedStore.remove(rrec);
}
}, this);
}, this);
},
})
Binding the value:
{
xtype: 'rtagfield',
fieldLabel: 'Sales Department',
name: 'id',
displayField: 'name',
valueField: 'id',
bind: {
store: '{salesDepartment}',
value: '{record.salesDepartment}'
}
},
And adding a definition for the association:
Ext.define('MyApp.model.User', {
extend: 'Ext.data.Model',
alias: 'model.user',
hasMany: [{
model: 'MyApp.model.SalesDepartmentModel',
associationKey: 'salesDepartment',
role: 'salesDepartment'
}],
requires: [
'Ext.data.field.String'
],
fields: [{
type: 'string',
name: 'userName'
}, {
type: 'string',
name: 'firstName'
}, {
type: 'string',
name: 'lastName'
}, {
name: 'salesDepartment'
}, {
name: 'roles'
}, {
type: 'string',
name: 'email'
}, {
name: 'notificationFrequencyId'
}]
});
Further reading
I suggest you read more on associations and the tagfield source code
In terms of saving records back to the server, I would recommend looking at sessions

UIGrid (Angular JS) - having a dropdown in a table header column

I am using Angular 1.5 and am using the UI Grid. I was wondering is there a way to put a drop-down (i.e. a select) in a header column ? I know you can do it within the "data" cells/rows of the table but unsure if it can be done in the header title ?
See the below image link to see a visual of what I mean. I want to put the dropdown into the column header called "Value"
enter image description here
Thanks - Ronan.
You can specify a filter with selectOptions for displaying a dropdown in the header.
Example:
columnDefs: [{
name: 'id', field: 'id'
},
{
name: 'value', field: 'value',
filter: {
type: uiGridConstants.filter.SELECT,
selectOptions: [{ value: '1', label: 'One' },
{ value: '2', label: 'Two' }]
}
}]
For more details check filter section in this link UI Grid ColumnDef - Filters

Angular Ui Grid

apologies if this is really simple but....
I want to display a grid of data but need a look up for some columns. This will become an editable grid but I am suffering with the basics so god help me.
I have two sets of data:
$gridOptions1.data = [{"group_id":"1","location_id":"-1","group_name":"Cars","active":"1"},{"group_id":"2","location_id":"1","group_name":"Trains","active":"1"},{"group_id":"3","location_id":"2","group_name":"Buses","active":"0"}]
and
$scope.locations=[{value: "-1", text: 'All Locations'},
{value: "0", text: 'Location 1'},
{value: "1", text: 'Location 2'},
{value: "2", text: 'Location 3'},
{value: "3", text: 'Location 4'}];
And want to display in the grid.
$scope.gridOptions1 = {
enableSorting: true,
columnDefs: [
{ field: 'location_id' },
{ field: 'group_name' },
{ field: 'active' },
{ name: 'Location', field:'location_id', cellFilter: 'maplocation:this'}
],
onRegisterApi: function( gridApi ) {
$scope.grid1Api = gridApi;
}
};
What I need to do is map the location id
I thought I could use a filter but cannot seem to get access to the scope data.
If anyone could give me a simple example of how to do this I would be very grateful as I am struggling to find any examples of what I want to do.
From what I can see the 'this' parameter is a pointer to the record and not the scope in which the grid options is defined.
I don't want to define the data in the filter because it is coming from the database.
Hope that makes sense.
If you want to use part of the data that's in your application scope to transform the data displayed in UI grid it's best to go with a custom template and calling in the function from your template.
Something like this should work:
columnDefs: [
{ field: 'location_id' },
{ field: 'group_name' },
{ field: 'active' },
{ name: 'Location', field:'location_id', cellTemplate: 'location-template'}
],
And then HTML:
<script type="text/ng-template" id="location-template">
<div class="ui-grid-cell-contents" title="TOOLTIP">{{grid.appScope.formatLocation(row)}}</div>
</script>
Now all you have to do is to define function formatLocation in your controller's scope and do the magic there.
When calling functions from within the cell template, make sure you use grid.appScope to get access to your controller's scope, like in the example I've provided.
Thanks to #Ethnar, here is a workable solution that keeps the template in the source:
columnDefs: [ { field: 'location_id' },
{ field: 'group_name' },
{ field: active' },
{ name: 'Location', field:'location_id',
cellTemplate: '<div class="ui-grid-cell-contents" title="TOOLTIP">{{grid.appScope.formatLocation(row)}}</div>'
}],
Then all is needed is the formatLocation function:
$scope.formatLocation=function(row)
{
locationid=row.entity.location_id;
if(locationid && $scope.locations.length) {
var selected = $filter('filter')($scope.locations, {value: locationid});
return selected.length ? selected[0].text : 'Not set';
} else {
return 'Not set';
} };

Resources