Dropdown with DataTables + JEditable

Dropdown with DataTables + JEditable

gunbladeivgunbladeiv Posts: 2Questions: 0Answers: 0
edited June 2011 in Plug-ins
Hello,

I'm currently playing around with ASP.NET MVC 3 and display table using DataTables and make it editable inline by using JEditable plugin. But I have one problem with dropdown inline edit. I retrieve the data from SQL when user click to edit. How can I filter the dropdown list to only display items related to the user group id so that the load will be less each time user click to edit the column value.

this is my current code:
[code]
$(document).ready(function () {
$('#myItem').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": 'Items/AjaxDataProvider',
"sPaginationType": "full_numbers",
"aoColumns": [
{ "sName": "ID",
"bSearchable": false,
"bSortable": false,
"bVisible": false
},
{ "sName": "NAME", "sWidth": "20%" },
{ "sName": "UOM", "sWidth": "7%", "sClass": "uom" },
{ "sName": "REMARKS", "sWidth": "8%" },
{ "sName": "BARCODE", "sWidth": "8%" },
{ "sName": "WITH SERIAL", "sWidth": "10%" },
{ "sName": "REORDER", "sWidth": "7%" },
{ "sName": "CODE", "sWidth": "8%" },
{ "sName": "G230", "sWidth": "8%" },
{ "sName": "G233", "sWidth": "8%" },
{ "sName": "G234", "sWidth": "8%" },
{ "sName": "MODEL" }
]
}).makeEditable({
sUpdateURL: "/Items/UpdateData",
sAddURL: "/Items/AddData",
sDeleteURL: "/Items/DeleteData",
aoColumns: [
{},
{
sUpdateURL: "/Items/UpdateDataSelect",
data: uomList(),
type: "select",
onBlur: "submit"
},
{},
{},
{},
{},
{},
{
sUpdateURL: "/Items/UpdateDataSelect",
data: uomList(),
type: "select",
onBlur: "submit",
success : fnCallBack
},
{
sUpdateURL: "/Items/UpdateDataSelect",
data: grpList(),
type: "select",
onBlur: "submit"
},
{
sUpdateURL: "/Items/UpdateDataSelect",
data: grpList(),
type: "select",
onBlur: "submit"
},
{}]
});
});

function validateJSON(x) {
var orig = x;
var stgify = JSON.stringify(orig);
var splitchar = ['\\"', '\',\'', '[', ']', '\"'];
var joinchar = ['\'', '\':\'', '', '', ''];

for (i = 0; i < 5; i++) {
stgify = stgify.split(splitchar[i]);
tmp = stgify.join(joinchar[i]);
stgify = tmp;
}
stgify = "{" + stgify + "}";
var finalEdit = stgify;
return finalEdit;
}

function uomlist(id) {
$.post('Items/uomSelectList', {},
function (data) {
uomlist = validateJSON(data);
},
'json/javascript'
);
alert(id);
return uomlist;
}

function uomList() {
ulist = uomlist();
return ulist;
}

function grplist() {
$.post('Items/grpSelectList', {},
function (data) {
grplist = validateJSON(data);
},
'json/javascript'
);
return grplist;
}

function grpList() {
b = grplist();
return b;
}[/code]

And this is my ASP.NET MVC 3 Controller code:
[code]
public ActionResult uomSelectList()
{

var temp = db.SGMs.Where(c => (c.UGC.Length != 0))
.Select(c => new { c.GID, c.UGC });
var jsonUOMList = temp.Select(c => new[] { c.GID.ToString(), c.UGC.ToString() });
return Json(jsonUOMList);


}

public ActionResult grpSelectList()
{
var temp = db.SGMs.Where(c => (c.Desc.Length != 0))
.Select(c => new { c.GID, c.Desc });
var jsonGRPList = temp.Select(c => new[] { c.GID.ToString(), c.Desc.ToString() });
return Json(jsonGRPList);
}
[/code]

I would like to use the records ID which is not show on the tables as reffences to fetch Dropdown value list from SQL. So then my controller will look like this:

Replies

  • gunbladeivgunbladeiv Posts: 2Questions: 0Answers: 0
    edited June 2011
    [code]
    [HttpPost]
    public ActionResult uomSelectList(int id)
    {

    var temp = db.SGMs.Where(c => (c.UGC.Length != 0) && (c.SID = id))
    .Select(c => new { c.GID, c.UGC });
    var jsonUOMList = temp.Select(c => new[] { c.GID.ToString(), c.UGC.ToString() });
    return Json(jsonUOMList);


    }
    [HttpPost]
    public ActionResult grpSelectList(int id)
    {
    var temp = db.SGMs.Where(c => (c.Desc.Length != 0) && (c.SID = id))
    .Select(c => new { c.GID, c.Desc });
    var jsonGRPList = temp.Select(c => new[] { c.GID.ToString(), c.Desc.ToString() });
    return Json(jsonGRPList);
    }
    [/code]

    Anyone got any advise and want to propose a workaround for my problem? I'm really stuck and no progress for about 6-7 hours. BTW thanks in advanced.
This discussion has been closed.