首页 > 解决方案 > Datatable contenteditable问题导致scrollX

问题描述

我对 contenteditable 有疑问。

当我在列上使用 contenteditable 并且启用 scrollX 选项时,列未对齐。看我的截图错位了

我在stackoverflow上尝试了很多解决方案,但都没有成功。

但是,这是我的 dataTable 设置:

table = $('#sparepart_id').DataTable({
    "paging": true,
    "stateSave": true,
    "pagingType": "full_numbers",
    "lengthChange": false,
    "searching": false,
    "ordering": true,
    "info": false,
    "autoWidth": false,
    "pageLength": 12,
    scrollX: true,
    "initComplete": function (settings, json) {  
        $("#sparepart_id").wrap("<div style='overflow:auto; width:100%;position:relative;'></div>");            
      },
   stateLoadCallback: function (settings) {
     var o;
     $.ajax( {
        url     : BASE_URL+"spareparts/load_layout",
        type    : "POST",
        data    : { module_table : "sparepart-list"},
        async   : false,
        dataType: 'json',
         success: function (json) {
             o = JSON.parse(json.json);
         },
         error:function(data){
            console.log(data);
         }
     } );
     return o;
 }

在我的 HTML 代码中

<td contenteditable="true"></td>

标签: javascriptphpjquerycodeigniterdatatable

解决方案


不必将此标记为解决方案,也不必投票。这个答案是由这个问题的作者找到的。我列出了这个,以保留 SO 中遵循的问答模式

.class{
word-break: break-all !important;
cursor: text;
white-space: pre-wrap !important;
}

推荐阅读