jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Jqxgrid width column jqxdropdownlist
This topic contains 10 replies, has 2 voices, and was last updated by Hristo 8 years, 9 months ago.
-
Author
-
Hi, I´m using jqxdropdownlist inside jqxgrid. In function initeditor I need get ‘value’ dropdownlist and no ‘label’, cellvalue is always label, I need ‘value’.
My dropdown code:
var locallista = [{ value: “5289”, label: “Americanas”},
{ value: “5290”, label: “Loja 01”}
];var locallistaSource = {
datatype: “array”,
datafields: [ { name: ‘label’, type: ‘string’ }, { name: ‘value’, type: ‘string’ } ],
localdata: locallista
};var locallistaAdapter = new $.jqx.dataAdapter(locallistaSource, {
autoBind: true
});{columns: [
{ text: “Local Lista”, width: “100”, dataField: “7115”, columntype: ‘custom’,
createeditor: function (row, column, editor) {
editor.jqxDropDownList({source: locallistaAdapter, displayMember: ‘label’, valueMember: ‘value’, filterable: false,
placeHolder: ‘Choose…’});},
initeditor: function (row, cellvalue, editor) {
editor.jqxDropDownList(‘selectItem’, cellvalue);
}},
}In my list I have value: “5289”, label: “Americanas”, I want get value : “5289” in initeditor
Best Regards
Hello GabrielCostaAlves,
Please, take a look those examples:
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/gridkeyvaluescolumnwitharray.htm?light
https://www.jseditor.io/?key=grid-with-dropdownlistBest Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comHi, Thanks for the answer.
But I need get de value using initeditor.
I want use:
initeditor: function (row, cellvalue, editor) {
editor.jqxDropDownList(‘selectItem’, cellvalue);
}}.But cellvalue is label, then I need value dropdown.
Or, Is there another way to set the selected value during initeditor?
Tks
Best Regards
Hello GabrielCostaAlves,
You could try to use setContent.
About this ( editor.jqxDropDownList(‘selectItem’, cellvalue); ) row in your code is no matter to use because in that moment when try to select item is the exactly same.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comHi,
But if I use setContent, I´m setting new content. I don´t want this. I want set some value of my list as content.
var locallista = [{ value: “5289”, label: “Americanas”},
{ value: “5290”, label: “Loja 01”}
];Example:
initeditor: function (row, cellvalue, editor) {
editor.jqxDropDownList(‘setContent’, cellvalue);
}}.If I use this, I´m setting the label, but I want set the value of my list.
I Try this, It´s work.
initeditor: function (row, cellvalue, editor) {
editor.jqxDropDownList(‘setContent’, 5289);
}}.But, I want this dynamically. For Example:
editor.jqxDropDownList(‘setContent’, value);
Best Regards
Hello GabrielCostaAlves,
Please, take a look this example:
https://www.jseditor.io/?key=grid-with-dropdownlist
Could you tell what you want to achieve and what is not right if we based on the example above?Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comHi,
I want achieve the value jqxdropdown, not label.
In your example, You are using $(“#jqxgrid”).on(‘cellvaluechanged’, function (event), I want uset initeditor.
I found a workaround , but it’s not the ideal, because if I have equals labels, I don´t know what value.
My solution:
initeditor: function (row, cellvalue, editor) {
var items = editor.jqxDropDownList(‘getItems’);
var value = getListValue(items, cellvalue);
editor.jqxDropDownList(‘selectItem’, value);
}function getListValue(items, value) {
for (var i = 0; i < items.length; i++) {
if (value == items[i].label) {
return items[i].value;
}
}
}Based in my solution, Do you have other suggestions?
Best Regards.
Hello GabrielCostaAlves,
I guess it’s a little confusing with this example.
In my example has two columns in the Grid. First column ‘Value’ represent the id of the item (it is equal to your data ‘values’).
Second column ‘Local Lista’ represent the name of the item (it is equal ‘label’ from data (locallista)).
This is not editable column, it is used only to shows the name of the chosen element.
In the first column I was thinking you want to show some title of the element (in my case combination from “id” + “name” it is equal to [label + ‘ – ‘ + value]).
If you would like to change simply change returned string inrenderer
of the jqxDropDownList.
I asked you ‘what you want to achieve’ because I would like to create the example together with you and with the behavior that you want.
Please, take a look this example.
I have one suggestion about your getListValue function could search by ID and return the desired value.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comHi,
I forgot, but I´m using editable column.
I need after click in edit button get value in my data and use in editor.jqxDropDownList(‘selectItem’, value); inside initeditor
Hi,
Your example work now. But I have one problem.
The same problem my function getListValue, the problem is when have two name (label) equals.
Insert in your example the follow data and you see the problem:
This because the displayMember needs name, not id.
var locallista = [
{ id: “5289”, name: “Americanas” },
{ id: “5290”, name: “Loja 01” },
{ id: “5302”, name: “Loja 01” }
];In this case the value is always 5290, because is the first.
After this I need getValue, for example, I select “Americanas”, then I want “5289”
Best Regards.
Hello GabrielCostaAlves,
Please, take a look this example:
https://www.jseditor.io/?key=grid-with-dropdownlist-edited2
You could get ‘id’ with bind to ‘cellvaluechanged’ because in this scenario ‘geteditorvalue’ callback will return the name of this item.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.