ソースを参照

Added logic for onClickCell and onDblClickCell to initBody

This allows for developers to listen for cell click and cell dblclick
events. The logic gets the cellIndex from the target <td>, then
selects corresponding <th> from this.$header using the "eq()"
selector. Using the 'field' from the header cell's data, the value is
selected from the data to be passed to the new events.

The key changes are as follow:
- 'click-cell' is fired at the same time as 'click-row'
- 'dbl-click-cell' is fired at the same time as 'dbl-click-row'
- changed selector of the dblclick event to "> tr > td"
jtrumbull 10 年 前
コミット
ec97ec9593
1 ファイル変更19 行追加4 行削除
  1. 19 4
      src/bootstrap-table.js

+ 19 - 4
src/bootstrap-table.js

@@ -1364,8 +1364,15 @@
 
         // click to select by column
         this.$body.find('> tr > td').off('click').on('click', function () {
-            var $tr = $(this).parent();
-            that.trigger('click-row', that.data[$tr.data('index')], $tr);
+            var $td = $(this),
+                $tr = $td.parent(),
+                item = that.data[$tr.data('index')],
+                cellIndex = $td[0].cellIndex,
+                $headerCell = that.$header.find('th:eq(' + cellIndex + ')'),
+                field = $headerCell.data('field'),
+                value = item[field];
+            that.trigger('click-cell', value, item, $td);
+            that.trigger('click-row', item, $tr);
             // if click to select - then trigger the checkbox/radio click
             if (that.options.clickToSelect) {
                 if (that.header.clickToSelects[$tr.children().index($(this))]) {
@@ -1374,8 +1381,16 @@
                 }
             }
         });
-        this.$body.find('tr').off('dblclick').on('dblclick', function () {
-            that.trigger('dbl-click-row', that.data[$(this).data('index')], $(this));
+        this.$body.find('> tr > td').off('dblclick').on('dblclick', function () {
+            var $td = $(this),
+                $tr = $td.parent(),
+                item = that.data[$tr.data('index')],
+                cellIndex = $td[0].cellIndex,
+                $headerCell = that.$header.find('th:eq(' + cellIndex + ')'),
+                field = $headerCell.data('field'),
+                value = item[field];
+            that.trigger('dbl-click-cell', value, item, $td);
+            that.trigger('dbl-click-row', item, $tr);
         });
 
         this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));