简体   繁体   中英

Can't select a row in jquery datatable

I followed the instructions http://editor.datatables.net/examples/inline-editing/simple.html and wrote the following code:

  $(document).ready(function() {
  var editor_basic = new $.fn.dataTable.Editor({
      ajax: "/webmaster/wordbag/treeForm",
      table: "#wordbag_basic_table",
      fields: [{
              label: "wordbag",
              name: "wordbag"
          }
      ]
  });

  $('#wordbag_basic_table').on( 'click', 'tbody td:not(:first-child)', function (e) {
      editor_basic.inline( this );
  });

var basic = [
    {'DT_RowId': 1 ,
    'wordbag':  'hello',
    'parentID': 4,
    },
];

var datatable_basic = $('#wordbag_basic_table').DataTable({
    dom: "Bfrtip",
    data: basic,
    language: {
        paginate: {
            previous: '‹',
            next:     '›'
        },
        aria: {
            paginate: {
                previous: 'Previous',
                next:     'Next'
            }
        }
    },
    columns: [
      {
      data: null,
      defaultContent: '',
      className: 'select-checkbox',
      orderable: false,
      },
      { data: "wordbag" },
    ],
    select: {
      style: 'os',
      selector: 'td:first-child',
    },
    buttons: [
      { extend: "create", editor: editor_basic },
      { extend: "edit",  editor: editor_basic },
      { extend: "remove", editor: editor_basic },
    ]
});

But when I click on the first column like a select box, the row couldn't be selected.So I can't edit or delete the row. Could you help me figure out?

Maybe my answer is too late but it will be usefull for future users.

The first step you should do is to create a quite simple html file where you include all the css and jss you use exactly on your current project. There are :

  • datatable css
  • datatable select css (or other extensions css)
  • jquery js
  • datatable js
  • datatable select js (or other extensions js)

Then you test if it works. I'm pretty sure it will not work and the reason is the versions of those stuffs you use.

So you should find which file you should change. They don't play well together. For me, I swicth to the last jquery datatable js and it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM