数据表可编辑选择不填充

时间:2015-01-14 16:23:19

标签: javascript jquery json datatables jeditable

我正在使用jquery-datatables-editable来编辑表格。一切都适用于文本输入和日期选择器,但是当我尝试填充选择时,它总是空的。

我使用的代码是:

$("#eventsTable").dataTable(
{
    "bPaginate": false,
    "bInfo": false,
    "bLengthChange": false,
    "bFilter": false,
    "aoColumnDefs": [ {
        "bSortable": false,
        "aTargets": [5]
    } ],
    "sPaginationType": "full_numbers",
    "oLanguage": {
        "sEmptyTable": "<%=LanguageFieldsList.translate("There are no events")%>"
    }
})
.makeEditable(
{
    sUpdateURL: "ForecastManager?cmd=updateForecastEvent",
    aoColumns: [
        {
            indicator: "<img src='/Shared/img/loading.gif' alt='Saving...'/>",
            event: "click",
            type: "text",
            onblur: "submit"
        },
        {
            indicator: "<img src='/Shared/img/loading.gif' alt='Saving...'/>",
            event: "click",
            type: "datepicker",
            datepicker: {
                dateFormat: datePickerDateFormat,
                monthNamesShort: datePickerNames.monthNamesShort,
                dayNamesMin: datePickerNames.dayNamesMin,
                changeMonth: true,
                changeYear: true
            },
            onblur: "submit"
        },
        {
            indicator: "<img src='/Shared/img/loading.gif' alt='Saving...'/>",
            event: "click",
            type: "datepicker",
            datepicker: {
                dateFormat: datePickerDateFormat,
                monthNamesShort: datePickerNames.monthNamesShort,
                dayNamesMin: datePickerNames.dayNamesMin,
                changeMonth: true,
                changeYear: true
            },
            onblur: "submit"
        },
        {
            indicator: "<img src='/Shared/img/loading.gif' alt='Saving...'/>",
            event: "click",
            type: "text",
            onblur: "submit"
        },
        {
            indicator: "<img src='/Shared/img/loading.gif' alt='Saving...'/>",
            event: "click",
            type: "select",
            onblur: "submit",
            loadurl: "ForecastManager?cmd=loadForecastEventSelect"
        }
    ]
});

正如您所看到的,当您点击最后一列时,我试图通过转到“ForecastManager?cmd = loadForecastEventSelect”填充选择,这可以工作并返回JSON字符串:

{"0": "No Event","1": "Event 1","2": "Event 2"}

但是select是空白的,但是当我直接将这个JSON字符串作为数据选项时:

{
    indicator: "<img src='/Shared/img/loading.gif' alt='Saving...'/>",
    event: "click",
    type: "select",
    onblur: "submit",
    data: '{"0": "No Event","1": "Event 1","2": "Event 2"}'               
}

这会成功填充选择。有没有人知道为什么当我使用loadurl时,JSON被忽略了?

更新:

我发现问题是因为我将响应内容类型设置为application / json。将其更改为text / html会成功填充选择。

0 个答案:

没有答案