How to use dropdown list in Datatable in Inline editing

前端 未结 2 1820
臣服心动
臣服心动 2021-01-05 19:59

I am using datatable 1.8 its amazing, I have recently read an article regarding inline editing of datatable column, Inline editing , in this article on clicking on edit hype

2条回答
  •  感动是毒
    2021-01-05 20:29

    There is a way to obtain a JSON array for filling a dropdown list in the moment when you make a click to "edit" link, that way is get your JSON through "complete" rather "success" attribute of your AJAX call inside "fnServerData" like this:

    "fnServerData": function(sSource, aoData, fnCallback, oSettings) {
                        oSettings.jqXHR = $.ajax({
                            "dataType": 'json',
                            "type": "POST",
                            "url": sSource,
                            "data": "opcionesMenu=ini",
                            "success": fnCallback,
                            "complete": function(resp) {
                                    jsonSelects = JSON.parse(resp.responseText);
                            }
                        });
                    }
    

    In my example "jsonSelects" is a global variable where I can obtain my JSON everywhere inside my code, then I will use my JSON to fill a dropdown list when editing like this:

    function editRow(oTable, nRow)
            {
                var aData = oTable.fnGetData(nRow);
                var jqTds = $('>td', nRow);
    
                //Dropdown list
                jqTds[2].innerHTML = '';                    
                    for(i = 0; i < jsonSelects.menu.length; i++) {
                          $('#selMenu').append('');
                    }
    
                    //Dropdown list
                    jqTds[3].innerHTML = '';                    
                    for(i = 0; i < jsonSelects.idioma.length; i++) {
                          $('#selIdioma').append('');
                    }
                    // Input text
                    jqTds[4].innerHTML = '';
    

    When you click in the "edit" link you will get a dropdown list in the fields that you wanted.

提交回复
热议问题