1

I am using Entity Framework Database First approach in ASP.NET MVC.

I have created models from an existing database and everything works fine.

I am using jqGrid and trying to create a drop down list for a column which is defined as an Int in the database.

In the database, the values are either 0 or 1, so in the dropdown list I will have to show two values such as "Import" or "Export" based on whether it is 0 or 1.

Would I be able to handle this scenario in the jqGrid?

Please post any suggestions if you have!

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
inspiringmyself
  • 590
  • 1
  • 11
  • 29
  • "drop down list for a column" can you elaborate on this pls – Yasser Shaikh Aug 08 '12 at 17:39
  • @Yasser: I have a column in the database which is an Int and contains 0 or 1. I am using jqGrid and when displaying the table, I want to show the text "Import" for 0 and "Export" for 1. And when I Add/Edit a row, I want to display a dropdown list with values "Import" and "Export", so that they can select one of these values, but when I save it to the database, I need to save as 0 or 1. Am I clear enough? – inspiringmyself Aug 08 '12 at 17:42
  • yes clear enuf ! now tell me what have tried ? – Yasser Shaikh Aug 08 '12 at 17:44
  • @Yasser: So far, I have dealt with this in a hard way. I was able to show the dropdown list when users Add/Edit in the model form but I ended up creating another string property in the Model class to hold the values "Import" and "Export". I am not sure whether there is an easy way to deal with this issue with the existing Int property. – inspiringmyself Aug 08 '12 at 17:53
  • @Yasser: Also, when the rows are displayed in the jqGrid, the specific column is not displaying "Import" or "Export" since the column can only display either 0 or 1 and that makes sense, but I want it to display "Import" or "Export" based on 0 or 1. Is there an easy way to deal with all these problems? Please suggest! – inspiringmyself Aug 08 '12 at 17:53

1 Answers1

0

I think you can handle this thing in colModal itself. there's is one option editOption you can specify with you colModal and based on the value you are getting from data you can specfy the text property of that column

In this case, the data for the grid should contain “One” or “Two” to be set in the column myname.

Now, with this setting

<script>
jQuery("#grid_id").jqGrid({
...
   colModel : [ {name:'myname', edittype:'select', formatter:'select', editoptions:{value:"1:One;2:Two"}} ... ]
...
});
</script>

the data should contain the keys (“1” or “2”), but the value (“One”, or “Two”) will be displayed in the grid.

check this link for further help. You will get your answer. Because you didn't post your code(atleast you should have done that for ur that particular column) i can not say you are implementing the same way.

Piyush Sardana
  • 1,748
  • 4
  • 19
  • 33
  • Thanks for your time. Actually, I am using "buildSelect" instead of "value", but I tried this editoption (value) and yes, in the Add/Edit options it shows the dropdown list with One and Two but when the grid displayed, it is not showing the "One" or "Two" for that particular column, since it is an Int column in the database and in the model, it is an Int property so it not showing the strings "One" or "Two" in the column itself. Hope you understand my problem! By the way, I couldn't find any link above. – inspiringmyself Aug 09 '12 at 15:25
  • see these two links http://stackoverflow.com/questions/2581384/how-to-get-selects-value-in-jqgrid-when-using-select-editoptions-on-a-column in this answer number and check the link provided in ans 2 – Piyush Sardana Aug 09 '12 at 16:32
  • http://stackoverflow.com/questions/4469650/jqgrid-incorrect-select-drop-down-option-values-in-edit-box check this linka lso – Piyush Sardana Aug 09 '12 at 16:33
  • Thanks, I will check them out. – inspiringmyself Aug 09 '12 at 17:28