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

colModel formatter is not working correctly #439

Open
AverageGuy opened this issue Jul 19, 2018 · 1 comment
Open

colModel formatter is not working correctly #439

AverageGuy opened this issue Jul 19, 2018 · 1 comment

Comments

@AverageGuy
Copy link

I have a piece of code that was working fine with and earlier version of jqGrid(pre the fork) and when I attempted to upgrade it the formatter function stopped working.

Code snippet:
function preferredSelect(cellvalue,options,rowObj) { var id = rowObj.contactid; var current=cellvalue; console.log(cellvalue); console.dir(options); console.dir(rowObj); if(cellvalue==undefined) id=newRow; var str = "<select id=\"ispref_"+id+"\">"; if(cellvalue=="N") str +="<option SELECTED value=\"N\">N</option>"; else str +="<option value=\"N\">N</option>"; if(cellvalue=="Y") str +="<option SELECTED value=\"Y\">Y</option>"; else str +="<option value=\"Y\">Y</option>"; console.log(str); return str;
From definition:
` {
name: 'ispreferred',
index: 'ispreferred',
editable:true,
formatter:preferredSelect,
width: 140,
userdata:'userdata',
cellattr: function(rowId,val,rawObject,cm,data) {
},
sorttype: "text"
},

`
Example output, note instead of a select element, the text is printed. What changed?
screenshot at 2018-07-19 09-16-30

@OlegKi
Copy link
Member

OlegKi commented Jul 24, 2018

Sorry for the late answer. Please, post always the version of jqGrid, which you use. Please, describe the problem more detailed, so that I could reproduce the problem. It's strictly recommended to post the demo (in JSFiddle, for example) which could I use to reproduce the problem and to debug it.

Your current JavaScript code is very dirty. The formatter generate wrong formatted HTML fragment, because the closing </select> is missing. Additionally the column has property editable: true. It's unclear for me how you plan to combine select displayed in the main grid with editing of data. The select looks for the user as if one can change the value directly without starting any editing. If the user makes the changes then jqGrid don't get any information about that. One can implement the code, which displays interactive element like select or chechbox without enable editing, but it's a little tricky. See the answer for references to a possible solution. I'm not sure that you use the grid correctly, but I'm not sure and I can't gives you any advices without seeing more full code.

The picture, which you posted seems as if multiple rows are in editing. When you have the problem? At the beginning by initial displaying the grid or later during starting some editing mode (inline editing or cell editing)?

In any way if you define custom formatter and use use editable: true, then you have to define unformat too (see here). Unformatter will be used by jqGrid to get the data from a custom formatted cell. The editing data will be the content of the cell if no unformat is defined. In the case you can have the results close to the results displayed on your picture.

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

No branches or pull requests

2 participants