Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Grid dropdown empty space item display #3942

Closed
ArunMNew opened this issue Jul 7, 2015 · 18 comments
Closed

UI Grid dropdown empty space item display #3942

ArunMNew opened this issue Jul 7, 2015 · 18 comments

Comments

@ArunMNew
Copy link

ArunMNew commented Jul 7, 2015

Hi,

In UI Grid when i use "'ui-grid/dropdownEditor" editableCellTemplate for display the dropdown
by default it shows an extra empty space item as first index along with actual itemsource.

I want to load actual itemsource without any selected item ...

Is there anyway to remove/hide that empty space item ?

uigriddropdown

@kranthikumar-polasa
Copy link

that empty space item rendered in the html ( )
Temp Solution is we can remove it by CSS trick like

#GridCustomId.ui-grid-cell div select option:first-child[value=""] {
display: none;
}
image

In the above screen selected html is the empty space item, i am identifying that using first-child[value=""].

@ArunMNew
Copy link
Author

ArunMNew commented Jul 8, 2015

@Kranthikumar2555 , i have tried your suggestion with below steps, but it does not help.

Please tell me what i am doing wrong here.

below is the html div which renders the ui grid.

<div ui-grid="gridOptions" ui-grid-edit class="grid"></div>

i have added style as below.
<style>
#gridOptions.ui-grid-cell div select option:first-child[value=""] {
display: none;
}
</style>

@JLLeitschuh
Copy link
Contributor

You need to set the id of the dom element you are using the directive on. In your case:

<div id="GridCustomId" ui-grid="gridOptions" ui-grid-edit class="grid"></div>

With the style:

<style>
  #GridCustomId.ui-grid-cell div select option:first-child[value=""] {
    display: none;
  }
</style>

Lookup how CSS selectors work in order to understand how #GridCustomId.ui-grid-cell div select option:first-child[value=""] is resolved.

@ArunMNew
Copy link
Author

ArunMNew commented Jul 9, 2015

@JLLeitschuh , i created sample plunker and did the same above approach. Still issue was not resolved.

Please see the plunker http://plnkr.co/edit/vhAATILeLpfd2CJONKi6?p=preview

In this plunker page the "Gender" column dropdown has empty space item.
I have added that style in "main.css" file.

@bernhard-hofmann
Copy link

The blank value will be removed when you chose one of the options. AngularJS adds this blank option when your model value is not in the options for the drop down list. If you want it to default to a value, you should set that on the object that is bound to that row in your grid.

@ArunMNew
Copy link
Author

ArunMNew commented Jul 9, 2015

@bernhard-hofmann , so is it not possible to remove that blank option without setting to any default value (or) choose one of the options ?

@bernhard-hofmann
Copy link

If there wasn't a blank, which value would you expect to be selected?

The DDL (Drop Down List) will show the selected item when the list is not shown, so what you see there must be in the list. AngularJS doesn't make an assumption on your default, so it inserts a blank (to match your model). Once you select one of the options, the blank is no longer needed and removed for you.

@aarosil
Copy link

aarosil commented Aug 3, 2015

@bernhard-hofmann Should the above also apply if the choice was already set in the data? I see blank value as an option, even though my data has a value set. Is this because I am binding to object rather than ID ("field" prop of the columnDef points to an object). Is there some "track by" I can use to indicate what option is already selected in the data (such as with ng-options)?

@PaulL1
Copy link
Contributor

PaulL1 commented Aug 3, 2015

Often the trick is 1 v's "1" in your data. i.e. string v's numeric.

@aarosil
Copy link

aarosil commented Aug 3, 2015

Thanks for the confirmation I should be able to bind to an object, display it's "name" prop and not have a "blank" dropdown option.

I confirmed both my original data in the grid as well as the data in editDropdownOptionsArray both have numeric IDs.

I thought maybe the blank option appeared because I assigned the dropdown values after async call, but I see the blank option even when I hardcode the dropdown options.

Here I created a plunk, showing the blank option still appears, even when the data is already set to an identical option that appears in the editDropdownOptionsArray. (sorry for extra code, I forked from the plunk above).

http://plnkr.co/edit/vMLKBcysXI6FsoPb3wHc?p=preview

@prasannapethe
Copy link

@ArunMNew
just update the plunker with this you will get the output

.filter('mapGender', function() {
var genderHash = {
'male': 'male',
'female': 'female'
};
and

editDropdownOptionsArray: [
{ id: 'male', gender: 'male' },
{ id: 'female', gender: 'female' }
]

@jvquarck
Copy link

@JLLeitschuh had it right, try checking on the console which value is getting the option, since maybe it's "?" instead of "".
option:first-child[value="?"]

@AKASH124001
Copy link

I want to hide one specific value from editDropdownOptionsArray on the basis of some condition??
How can I do that??

@roshenpo007
Copy link

What was the fix for this issue ? Facing similar defect.

@jstallm
Copy link

jstallm commented Jan 18, 2017

I had the same issue (a blank item showing upon clicking the UI cell. The issue was due to the cell value not being within the defined/included editDropdownOptionsArray.

@ghost
Copy link

ghost commented Aug 1, 2017

I figured it out! The css that @JLLeitschuh posted is correct but the first-child value needs to be changed from "" to "?".

So this:
#GridCustomId.ui-grid-cell div select option:first-child[value=""] { display: none; }

Needs to become:
#GridCustomId.ui-grid-cell div select option:first-child[value="?"] { display: none; }

The blank value should no longer be displayed.

@gousdem
Copy link

gousdem commented Aug 31, 2017

I added those code , but the issue still not fix. Can you help me.

@Abhilash-Pokhriyal
Copy link

What finally worked for me is:-
#GridCustomId.ui-grid-cell div select option:first-child:empty { display: none; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests