PrimeNG Dropdown with filterMatchMode - primeng

I have a PrimeNG dropdown with 1000s of values. So I put in a filter.
Now the issue is I want to have a filter with something like "filterMatchMode = startwith" which we have for table filter columns.
The default implementation is "contains" which cannot be overridden by the "filterMatchMode" property like we have in tables.
Issue with this is that I have multiple values ending in "xyz" and I have a value which is "xyz". So I have to scroll all the way down to select the value.
What could be possible solutions?
Current Code which does not solve the problem:
<p-dropdown [options]="myOptions" [(ngModel)]="selectedModel" filter="true" placeholder="Select a Model"
[style]="{'width':'200px'}">
</p-dropdown>

Only thing I can think of is to make a full copy of the primeNG dropdown component to change it.
They use a filter method in an objectutils class to filter. This method is using indexOf to do the filtering, you could replace it with contains.

Related

How to create drop down with form in AngularJS

I am trying build drop down with form like this. I used ng-repeat inside li to build a simple dropdown and then placed them inside next to another. the number of columns can also can be dynamic so my approach wont work. How do I proceed to build such a dropdown. Is there any library out there that does this I could not find one.Thanks in advance.
If you want to do this with Angular, you will need to toggle a dropdown. The following example should be able to get you started: http://jsfiddle.net/Lvc0u55v/10630/
You will need to compose the columns and associate them with the ng-model.
On Operator field you can do the following:
<input ng-model="operator"/>
<li ng-repeat="result in results | filter:operator</li>

Don't show dropdown choices with angular-ui-select before entering data?

I am using the angular-ui-select directive to create an auto-complete input field. I want to be able to click and focus the field without the dropdown options appearing. The Plunker example in the documentation works this way, but I cannot get mine to behave correctly. Please help.
Here is my code:
<ui-select ng-model="customer.selected" theme="bootstrap">
<ui-select-match placeholder="Start typing..">{{ $select.selected.family_name }}</ui-select-match>
<ui-select-choices repeat="customer in customers | filter: $select.search">
<div ng-bind-html="trustAsHtml((customer.family_name | highlight: $select.search))"></div>
</ui-select-choices>
</ui-select>
Here is their Plunker example that is working the way I would like it to.
http://plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview
I have a same issue. I want to be able to click and focus the field without the dropdown options appearing.
Here I am sharing my solution. May be it will help someone. I made changes in Selectize theme example in plunker shared by #Corey Quillen. I had cleaned up other things so it will help.
1) Here first I had add reset-search-input="false" in ui-select directive. So it will not reset search input.
2) Then I had replaced filter with custom filter propsFilter. Which is already useing in Select2 theme. And put
if(!props.name.length){
return out;
}
in filter above If condition. In demo.js file.
So data return empty if no search text entered.
Here is the plunker example of that.
ui-select by default shows a dropdown, I dont think we can change that. But you can change its binding data. In the plunker example the ui-select is bind to model 'address.selected', which initially is empty, thus nothing pops up. But once you start typing the refresh will call the function refreshAddress() to populate the results into address. Once the results are populated, ui-select finds that its model(address) has data and start showing a dropdown. After you have searched for something, try to click on the textbox, it will still show you the result, beacuse they are still present in the model.
Since, you are trying it with a local variable I suppose, it is pre-populated with data for ui-select and hence it shows it. I think you should try to make a request in you code to get that data and use refresh and refresh-delay. If you dont have a web service and want to use local data, I would suggest bind the select to an empty model and put data into that using a custom function for refresh, you might have to write a custom search functionality into the refresh function, but you can use javascript's search() or indexOf() for that.

Angular UI bootstrap: Type ahead select multiple

I am using angular UI bootstrap type-ahead directive for type-ahead in a form
http://angular-ui.github.io/bootstrap/
I am fetching the records from remote server via $http service. It is working fine.
However I can select only one element from list at a time.
I want to select multiple values from the list and show all currently selected element in input field with a remove button just like tags for SO. The selected tags are stored in angular array model.
How to achieve this ?
I have read documentation for Angular UI bootstrap but I am not able to find anything.
This guy made a directive for this. Should do exactly what you want and it's even using the ui-bootstraps typeahead.
https://github.com/mbenford/ngTagsInput
The best solution I have found so far is io.select
it does exactly what you require, multi-select typeahead.
and the markup is neat and clean too e.g:
<oi-select
oi-options="list.id as list.description for list in lists"
ng-model="tags"
multiple
placeholder="Select">
</oi-select>
This component is also compatible with bootstrap and the new bootstrap 4.
In js file :
To list all selected items, use $item with typeahead-on-select and push to an array for ex.evtMem. delete fn to delete selected item.
HTML :
Use table to list all array values using ng-repeat. Addition to that add remove glyphicon image and function to delete corresponding item.

How do I apply filter in ExtJS

I am using :
Ext.ux.grid.FiltersFeature
It works fine, but whenever I load my store data
tablePanel.store.loadData(..)
the filters are not respected. The columns are visually selected as filtered (ie. greyed out), but all the rows are shown instead of the filtered subset of rows.
Here is the bug trapped in a JSFiddle :
http://jsfiddle.net/oliverwatkins/7hbt79bj/4/
To reproduce my problem :
Select column filter on Name, to the value 'foo'
Now only one row should show (the foo row)
Now click on Reset.
The filter is set to only show 'foo', but it shows 'bar' as well.
I know there is a method which removes filters :
grid.store.clearFilter();
I am looking for a method like this :
grid.store.applyFilters();
So I can execute it after I refresh the data in my table.
** UPDATE **
If I dig a bit deeper I can see that in the table panel there is a filter string being set.
tablePanel --> filters --> filters --> items --> [1] --> inputItem --> value = 'mySearchString'
However that is the filters on the tablePanel. If I look at the tablePanel-->store instead, I find filters with no items set :
tablePanel --> store --> filters --> filters --> items --> [0]
It is almost as if there are two different filtering systems at play here which are not communicating with each other.
And what makes things all even more infuriating is that store has a filter method, and grid does not have a filter method.
grid.store.filter(); //method exists
grid.filter(); //crashes
puzzling..
I used your fiddle and came up with a solution that sets the values after store load. After grid.store.loadData I added this code that reapplies the filters one by one.
var filterData = grid.filters.getFilterData();
Ext.Array.each(filterData, function(filter){
grid.filters.filters.getByKey(filter.field).setValue(filter.data.value)
})
The problem here is that grid filters feature creates an interface to the underlying store filtering mechanism. If you bypass the feature interface and go directly down to the store, filters do not know about it and get confused.
Therefore, use only API defined by FiltersFeature and everything should work as expected. For example, to clear filters, use:
grid.filters.clearFilters()

AngularJS drop down (ng- options) not binding - string to object (initial selection)

I am having a problem binding data retrieved from the server to a drop down list. The main issue I think is the fact that the comparison is done on differing object types.
For example:
1. The object returned from the server contains a currency code string. we want this to be bound to an item in the dropdown list
"baseCurrencyCode":"GBP"
The view model returns the list of currencies.. These are returned as a list of currency objects with different properties
{"currencies":[{"id":1,"rateId":0,"abbreviation":"AFN","description":"Afghani","rate":0.0,"rateDescription":null,"languageCode":"en-gb","isDefault":true,"fullDescription":"AFN - Afghani - ","shortDescription":"AFN - Afghani"}}
etc.
Currently, I have got this working by writing a function to go through every property for every item in the list, find the correct property we wish to compare to - do the comparison and then return the initial selection.
When calling my save method I then need to manually bind the currency abbreviation to the object I wish to return to the server.
Surely there must be a better way to do this?
Some of my code for reference..
<select ng-model="selectedCurrency" ng-options="currency.shortDescription for currency in viewModel.currencies"></select>
// Call to my custom method..List, PropertyName, value to compare
$scope.selectedCurrency = InitialiseDropdown($scope.viewModel.currencies, "abbreviation", $scope.updatedObject.baseCurrencyCode);
// Code executed when saving - to bind the currency to the updated object
$scope.updatedObject.baseCurrencyCode = $scope.selectedCurrency.abbreviation;
Any help is appreciated!
EDIT
Sorry if I wasn't clear enough.. To summarise..
The main problem here is binding to the drop down and initial selection.
The object we are updating contains a parameter (string) of the currency abbreviation.
The list we select from is a list of currency objects. As these are two differing object types I have been unable to plug in angulars 2 way binding and have written some code to do this on initial retrieval and when saving.
The cleanest way to fix this would be to return a currency object in our retrieval instead of a simple string of the abbreviation, but this is not an option.
Is there a better way of enabling 2 way binding on different object types ?
Thanks again
It is not exactly clear what the problem is, but you can save yourself some work by binding the <select> to the currently selected currency object (so you don't have to look it up later).
select + ngOptions allow you to bind to one value while displaying another, with the following syntax:
<select ng-model="selectedCurrency"
ng-options="currency as currency.shortDescription
for currency in viewModel.currencies">
</select>
In the above example, $scope.selectedCurrency will be bound to the whole currency object, but currency.shortDescription will be displayed in the dropdown.
See, also, this short demo.
UPDATE:
In case you don't need to bind to the whole currency object, but just bind updatedObject's baseCurrencyCode property to the abbreviation of the selected (in dropdown) currency, you can do it like this:
<!-- In the VIEW -->
<select ng-model="updatedObject.baseCurrencyCode"
ng-options="c.abbreviation as c.shortDescription
for c in currencies">
</select>
// In the CONTROLLER
$scope.currencies = [...];
$scope.updatedObject = {
...
baseCurrencyCode: <baseCurrencyCodeFromServer>
};
See, also, that short demo.
I have had the same problem, ng-model and ng-option being from 2 different sources. My ng-model is bound to a value in a json object representing a chosen filename and my ng-option is a list of possible values taken from a csv file.
In the controller I am reading a directory via a Nodejs route, and creating a json array of filenames like this
var allCsvFiles = [{"name":"file1.csv"},{"name","file2.csv},etc..]
The current csv file, i.e. the selected one is stored in another json array
[{"date":"01-06-2017","csvfile":"file1.csv","colour":"red"},{...}, etc].
I was using the following code for the dropdown:
<select type="text" ng-model="file.csvfile"
ng-options="opt.name for opt in allCsvFiles track by opt.name"></select>
Which caused the current selection to be blank and if I selected an item from the dropdown it put [object],[object] as the current selection. If I stepped through the code I found that it seemed to be selecting {"name","file1.csv"} as the option and couldn't display it, this seemed odd as my ng-options selection looks like it should just return the value of "name" not the array entry. I tried many different ways to make this work but eventually I found that if I made the list of possible selections a plain javascript array:
var allCsvFiles = ["file1.csv","file2.csv", "file3,csv]
and changed the select to:
<select type="text" ng-model="file.csvfile" ng-options="opt for opt in allCsvFiles"></select>
then the dropdown selection worked as expected.
I may have missed some other obvious solution here, but as the array of json objects is one dimensional anyway it doesn't seem to be an issue.
It looks like the OPs question has been answered, I just thought I'd add this as it solved it for me.

Resources