Dropdown select shows value instead of showing text
Dropdown select shows value instead of showing text
Nwilliams8162
Posts: 30Questions: 4Answers: 0
As you can see, when I filter in a list of options on a select field, It defaults to showing the value instead of the text. I want it to only ever show the text and i'll utilize the value when using ajax.
Thanks
This discussion has been closed.
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Colin,
Here is the example:
https://codepen.io/nrwilliams/pen/NWxOgwz
Ah, I see, thanks for the test case. This thread here should help. The problem is that the value really is 1, so the table is displaying that. When the server responds to the update, it should send back the correct project name, probably with from a join (example here)
Colin
I am not sure I follow one hundred percent. Are you saying I need to revise the way my select options are set up?
I'm afraid I'm not quite following either .
Going back to your screenshot - in the
select
you have a label, but the cell below shows what appears to be an id value rather than a label.Generally I would expect the table to show the labels in the columns, and also in the
select
list. Is that not what you want - do you want to show the id value in the table?The codepen example doesn't work because there are no matching values for the options in the table. e.g. take the
Project
column - it shows8517
, but there is no option for that in thePPA_VPPAProductOptions
array (thus it defaults to1
which is the first and only option in that array).Could you clarify what behaviour it is you are looking for here?
Thanks,
Allan
Allan,
Sorry about that. I just updated the first column on that codepen. So, when you click on the field it gives you a dropdown that has one option that says "Test". Then when you commit that field it shows you the id or whatever is the value. Instead I want it to display "Test" and not 8517.
Any other guidance you can give?
Sorry - missed this one!
The problem you are having is that you are trying to have both the label and the value under a single parameter -
project
. It can't be both. Typically, what you would do is have (e.g.)projectId
andprojectName
(orproject.name
if you are joining tables in the database which is most likely).That way you can instruct DataTables to use the name for display and Editor to use the id as the value that is being edited.
If you have a look at this example you can see that in action. There I use
users.site
as the id, andsites.name
as the label. So there are two different data points, although they are linked (through the database).That's what Colin was driving at above - you need to separate the two so they can be used.
One way of doing that (if you can't include the project name in your data structure) is to use a client-side rendering function for your column. That could take the id of the project and look it up (ideally from another client-side array or object).
Allan
Hm, I tried and no luck. Just got the following error:
DataTables warning: table id=proposals-table-ppavppa183562 - Requested unknown parameter 'projectname' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4
Below is part of the group of data I am referencing. When I put project (which is the id number) in editor and projectname (Name of project) in the columns, that is when I was getting the error above.
project: result.getValue({name: 'custbody_pb_project'}),
projectname: result.getText({name: 'custbody_pb_project'}),
Also, here is what the editor side looks like:
{
type: 'select',
label: 'Project:',
name: 'project',
multiple: false,
//separator: ',',
options: jQuery(this).data('projectoptions')
}
Not sure what I am doing wrong as I noticed the example you sent did not have any options parameter, so not sure how those were coming in.
Are you able to update your Codepen example from above with the current state of play please? Are you getting the unknown parameter error on initial load of the table? That error means that
projectname
isn’t in the parameters available for the row (note that it is case sensitive - not sure if that is the issue or not).Allan
Okay I updated the pen after getting closer. It shows the names now but when you select the project to change, whenever you submit it, it submits the whole line and changes everything back to the value instead of the text.
Thanks for the update. The problem is you are still trying to use
projectname
as both the label and the value. The DataTable column should be showingprojectname
(it is), while the Editor field should be operating on the project id (it isn't - it is also usingprojectname
).So we need to update the Editor field to use
project
. You also need to tell Editor that when you activate an edit on theprojectname
column you actually want to editproject
- you usecolumns.editField
for that - e.g.editField: 'project'
.That gets us 90% of the way there. The final missing item is that the edit only edits the
project
value. DataTables is still showing the oldprojectname
. There are two ways to address this:project
id and get the label.1 is obviously the easiest, but it will depend a little on how closely this example matches what you are using on your page.
This example might also be of some help as it achieves basically what you are looking to do: http://live.datatables.net/layonado/2/edit .
Allan
Thanks!!! I got it working now. Only thing left though it seems to be submitting the whole line and autofilling some fields in that line vs just submitting the cell im editing. How can I fix that?
It should, by default, submit only the changed values (the question is normally how to make it submit all values!).
That it is submitting other values suggests that they are changing value for some reason?
Allan
I know, but if you look at the codepen as well it is doing that and I don't know how to stop it. Any recommendations from looking at that?
Really need help on this one. Can't get the form to stop submitting each row and just submit each cell as I edit.
Thanks
Hi,
If I add the following to your CodePen:
it shows the data that is used for edit and then what would be submitted. That turns out to be the following for the initEdit:
And preSubmit shows:
So Editor thinks those fields have changed value. If we take
settlementlocationname
as an example we can see:Original:
"settlementlocationname": "NYISO Zone G",
Current value:
"settlementlocationname": "",
It looks like that is suffering from the same issue we discussed before - the difference between the label and value.
If Editor is submitting a field, then it thinks there is a value change, and to resolve, there needs to not be a value change (assuming you don't want it to change!).
Allan
Okay, I am honestly at a loss at what to do now and we have to get this working for a major client of ours. My instance is different as I am loading in select options from a list on each editor. I get errors when the editor name and table data fields do not match.