我如何获得w2ui网格单元格值?

时间:2016-07-01 11:15:52

标签: w2ui

我想得到我的" id" w2ui网格的价值。记录来自数据库

  

栏:[
              {field:' id',标题:' ID',尺寸:' 50px' },               {field:' name',caption:' Name',size:' 300px'},]

我的功能

onDblClick: function (event) {

           var grid = this;
           event.onComplete = function () {
           var sel = grid.getSelection();
           console.log('my id value ' + sel.id);
      }

但没有出现。我做错了吗?

1 个答案:

答案 0 :(得分:3)

grid.getSelection() returns an array of selected recids, see the documentation.

You should change your code as follows:

$(function() {
  $('#grid').w2grid({
    name: 'grid',
    columns: [
      { field: 'id', caption: 'ID', size: '50px' }, 
      { field: 'name', caption: 'Name', size: '300px' }
    ],
    records: [
      { recid: 1, id: '1', name: 'Name 1' },
      { recid: 2, id: '2', name: 'Name 2' } 
    ],
    onDblClick: function(event) {
      var grid = this;
      event.onComplete = function() {
        var sel_rec_ids = grid.getSelection();
        if (sel_rec_ids.length) {
          var sel_record = grid.get(sel_rec_ids[0]);
          console.log('selected ID:', sel_record.id, '/ selected Name:', sel_record.name);
        } else {
          console.log("Nothing selected!");
        }
      }
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.js"></script>
<link href="https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.css" rel="stylesheet" />

<div id="grid" style="width: 100%; height: 150px;"></div>


Also let me quote something, that some else commented on one of your questions in 2013:

I see you've not accepted any answer to your questions. That kinda defeats the goal of Stack Overflow. It would be great if you could review all the questions you've asked, accept correct answers and give feedback on proposed solutions that don't work

相关问题