Reputation: 21
I'm using MVC5 and helper Lib.Web.Mvc.JQuery.JqGrid. I need to load the list, into edit cell, without the current record, for to get one filtered list of the same type.
I have to get this:
The list should show all categories except "Catergory 1.1".
The property affected, in my MODEL, is as follows:
[ScaffoldColumn(false)]
[JqGridColumnEditable(false)]
public int? CategoryPK { get; set; }
[DisplayNameLocalized("Category")]
[JqGridColumnSortable(true, Index = "CategoryPK")]
[JqGridColumnEditable(true, "List4DDL", "Categories", EditType = JqGridColumnEditTypes.Select)]
[JqGridColumnFormatter("$.ddlFormatter")]
public string Category { get; set; }
My action into controller "Categories"
public ActionResult List4DDL() {
var list = new Dictionary<int, string>();
try {
... my code to get list of categories
} catch {
...
}
return (PartialView("_Partial.DropDownList", list));
}
How can to send to action the edit row id, or the selected item, for get filtered list?
Upvotes: 1
Views: 194
Reputation: 21
SOLVED! Since it someone can have the same problem, i explain how did it.
I have modified, in my model, the dataannotation of property "Category" so:
[DisplayNameLocalized("Category")]
[JqGridColumnSortable(true, Index = "CategoryPK")]
[JqGridColumnEditable(true, "List4DDL", "Categories", EditType = JqGridColumnEditTypes.Select)]
[JqGridColumnFormatter("$.ddlFormatter", UnFormatter = "$.ddlUnFormatter")]
public string Category { get; set; }
Adding the attribute "UnFormatter", that is triggered when the cell is selected, after i have worked on view
Into view i have added this code:
<script type="text/javascript">
$(document).ready(function() {
@jqGrid.GetJavaScript();
... (other code fo my grid) ...
$.ddlUnFormatter =
function(cellvalue, options, rowObject) {
var recordID = -1;
if (options) {
if (options.rowId) {
recordID = options.rowId;
}
if (options.colModel) {
if (options.colModel.editoptions) {
if (options.colModel.editoptions.dataUrl && (options.colModel.editoptions.dataUrl.indexOf("?id=") < 1)) {
options.colModel.editoptions.dataUrl = options.colModel.editoptions.dataUrl + "?id=" + recordID;
}
}
}
}
return (cellvalue);
};
</script>
i add the id on the fly on the route that load the list. This is action in my controller:
public ActionResult List4DDL(int? id) {
var list = new Dictionary<int, string>();
try {
... (my code to get list of categories, filtered by id)
} catch {
...
}
return (PartialView("_Partial.DropDownList", list));
}
I hope i was helpful to someone.
Upvotes: 1