Browse Source

Merge pull request #901 from jtrumbull/issue-894

Issue 894: click-cell and dbl-click-cell events
文翼 10 years ago
parent
commit
e5bd168e26

+ 8 - 0
.gitignore

@@ -11,3 +11,11 @@ docs_
 
 
 # check the locale file on README
 # check the locale file on README
 check.js
 check.js
+
+# Common IDE files
+nbproject
+.~lock.*
+.buildpath
+.idea
+.project
+.settings

+ 25 - 1
docs/_i18n/en/documentation/events.md

@@ -28,6 +28,30 @@
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
+        <td>onClickCell</td>
+        <td>click-cell.bs.table</td>
+        <td>field, value, row, $element</td>
+        <td>
+        Fires when user click a cell, the parameters contains: <br>
+        field: the field name corresponding to the clicked cell<br>
+        value: the data value corresponding to the clicked cell<br>
+        row: the record corresponding to the clicked row, <br>
+        $element: the td element.
+        </td>
+    </tr>
+    <tr>
+        <td>onDblClickCell</td>
+        <td>dbl-click-cell.bs.table</td>
+        <td>field, value, row, $element</td>
+        <td>
+        Fires when user double click a cell, the parameters contains: <br>
+        field: the field name corresponding to the clicked cell<br>
+        value: the data value corresponding to the clicked cell<br>
+        row: the record corresponding to the clicked row, <br>
+        $element: the td element.
+        </td>
+    </tr>
+    <tr>
         <td>onClickRow</td>
         <td>onClickRow</td>
         <td>click-row.bs.table</td>
         <td>click-row.bs.table</td>
         <td>row, $element</td>
         <td>row, $element</td>
@@ -42,7 +66,7 @@
         <td>dbl-click-row.bs.table</td>
         <td>dbl-click-row.bs.table</td>
         <td>row, $element</td>
         <td>row, $element</td>
         <td>
         <td>
-        Fires when user click a row, the parameters contains: <br>
+        Fires when user double click a row, the parameters contains: <br>
         row: the record corresponding to the clicked row, <br>
         row: the record corresponding to the clicked row, <br>
         $element: the tr element.
         $element: the tr element.
         </td>
         </td>

+ 24 - 0
docs/_i18n/es/documentation/events.md

@@ -27,6 +27,30 @@
         args: datos del evento.</td>
         args: datos del evento.</td>
     </tr>
     </tr>
     <tr>
     <tr>
+        <td>onClickCell</td>
+        <td>click-cell.bs.table</td>
+        <td>field, value, row, $element</td>
+        <td>
+        Se ejecuta cuando el usuario le da click a una celda de la tabla, los parámetros contienen: <br>
+        field: el nombre del campo correspondiente a la celda hecho clic, <br>
+        value: el valor de datos correspondiente a la celda hecho clic, <br>
+        row: el registro que corresponde con la fila a la que se le dio click, <br>
+        $element: el elemento td.
+        </td>
+    </tr>
+    <tr>
+        <td>onDblClickCell</td>
+        <td>dbl-click-cell.bs.table</td>
+        <td>field, value, row, $element</td>
+        <td>
+        Se ejecuta cuando el usuario le da click a una celda de la tabla, los parámetros contienen: <br>
+        field: el nombre del campo correspondiente a la celda hecho clic, <br>
+        value: el valor de datos correspondiente a la celda hecho clic, <br>
+        row: el registro que corresponde con la fila a la que se le dio click, <br>
+        $element: el elemento td.
+        </td>
+    </tr>
+    <tr>
         <td>onClickRow</td>
         <td>onClickRow</td>
         <td>click-row.bs.table</td>
         <td>click-row.bs.table</td>
         <td>row, $element</td>
         <td>row, $element</td>

+ 27 - 4
src/bootstrap-table.js

@@ -246,6 +246,12 @@
         onAll: function (name, args) {
         onAll: function (name, args) {
             return false;
             return false;
         },
         },
+        onClickCell: function (field, value, row, $element) {
+            return false;
+        },
+        onDblClickCell: function (field, value, row, $element) {
+            return false;
+        },
         onClickRow: function (item, $element) {
         onClickRow: function (item, $element) {
             return false;
             return false;
         },
         },
@@ -374,6 +380,8 @@
 
 
     BootstrapTable.EVENTS = {
     BootstrapTable.EVENTS = {
         'all.bs.table': 'onAll',
         'all.bs.table': 'onAll',
+        'click-cell.bs.table': 'onClickCell',
+        'dbl-click-cell.bs.table': 'onDblClickCell',
         'click-row.bs.table': 'onClickRow',
         'click-row.bs.table': 'onClickRow',
         'dbl-click-row.bs.table': 'onDblClickRow',
         'dbl-click-row.bs.table': 'onDblClickRow',
         'sort.bs.table': 'onSort',
         'sort.bs.table': 'onSort',
@@ -1383,8 +1391,15 @@
 
 
         // click to select by column
         // click to select by column
         this.$body.find('> tr > td').off('click').on('click', function () {
         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', field, value, item, $td);
+            that.trigger('click-row', item, $tr);
             // if click to select - then trigger the checkbox/radio click
             // if click to select - then trigger the checkbox/radio click
             if (that.options.clickToSelect) {
             if (that.options.clickToSelect) {
                 if (that.header.clickToSelects[$tr.children().index($(this))]) {
                 if (that.header.clickToSelects[$tr.children().index($(this))]) {
@@ -1393,8 +1408,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', field, value, item, $td);
+            that.trigger('dbl-click-row', item, $tr);
         });
         });
 
 
         this.$body.find('> tr > td > .detail-icon').off('click').on('click', function () {
         this.$body.find('> tr > td > .detail-icon').off('click').on('click', function () {