1

Following from this article, I'm trying to use a dropdownlist when I'm editing one of the columns in the DataTable to which I have applied the jquery datatable and jEditable plugin.

In the initialization of jEditable:

$('#myDataTable').dataTable().makeEditable({
"aoColumns": [
{
    //Empty object is used for the default editable settings
},
null,//null for read-only columns
{
    indicator: 'Saving...',
    tooltip: 'Click to select town',
    loadtext: 'loading...',
    type: 'select',
    onblur: 'submit',
    loadurl : 'GetSelectList',
    loadtype : 'GET'
}
]
});

It calls the GetSelectList action in the server, but I don't know what type of data I should return to the client. I have a Category model which has id and name. I can get them by GetCategories function. I need the final selectlist to be something like:

<select name="category" id="country" rel="6">
                                    <option value="1">cate1</option>
                                    <option value="2">cate2</option>
                                    <option value="3">cate3</option>
                                    </select>  

I searched the net, and the only thing that I have found was an article in php, which is Greek to me.

4

1 回答 1

0

我有同样的问题。我不得不修改可编辑的代码来解决它。

首先,我将服务器中的列表重新作为 SelectListItem 的列表(具有以下属性:Value、Text、Selected):

listOfEentities.Select(c => new SelectListItem { Text = c.Name, Value = c.Id.ToString() });

然后,更改 jeditable 代码(在定义类型选择的部分,更改元素内容,如下所示):

select: {
           element : function(settings, original) {
                var select = $('<select />');
                $(this).append(select);
                return(select);
            },
            content : function(data, settings, original) {
                /* If it is string assume it is json. */
                if (String == data.constructor) {      
                    eval ('var json = ' + data);
                } else {
                /* Otherwise assume it is a hash already. */
                    var json = data;
                }
                var selected = '';
                for (var i in json) {
                    var item = json[i];
                    if (item.Selected)
                        selected = item.Value;
                    var option = $('<option />').val(item.Value).append(item.Text);
                    $('select', this).append(option);    
                }                    
                /* Loop option again to set selected. IE needed this... */ 
                if (selected != "") {
                    $('select', this).children().each(function () {
                        if ($(this).val() == selected ||
                            $(this).text() == $.trim(original.revert)) {
                            $(this).attr('selected', 'selected');
                        }
                    });
                }
            }
        }
于 2014-06-23T23:59:16.773 回答