datatables: how to change the value of a cell on spacebar?

apfz

I would like to change the value of a cell in datatables. The idea is to switch between pre-set values when pressing spacebar on a focussed cell. But i am not sure how to implement this.

I am initializing DataTable in the following way.

var table = $('#data-table').DataTable();

var keys = new $.fn.dataTable.KeyTable( table );

Anybody has a suggestion?

apfz

Appears that the documentation of KeyTables 2.0 is not updated yet. I managed to do it in the following way:

var table = $('#data-table').DataTable();
var keys = new $.fn.dataTable.KeyTable( table );

table.on( 'key', function ( e, datatable, key, cell, originalEvent ) {
    if (key == 32) { #32 for spacebar
        var currentStatus = cell.data();
        switch(currentStatus) {
            case 'p':
                cell.data('f');
                $(cell.node()).removeClass('status_p').addClass('status_f');
                break;
            case 'f':
                cell.data('h');
                $(cell.node()).removeClass('status_f').addClass('status_h');
                break;
            case 'h':
                cell.data('p');
                $(cell.node()).removeClass('status_h').addClass('status_p');
                break;
            default:
                cell.data('p');
                $(cell.node()).attr('class','').addClass('status_p');
        }
    }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to change specific jQuery dataTables cell value

From Dev

How to change cell color of datatables?

From Dev

How to get value from dropdown in datatables cell

From Dev

How to get value from dropdown in datatables cell

From Dev

DataTables - How do I get/set the value of a cell in a row?

From Dev

How to Change Conditional Formatting of a Cell Based on a Change in the Cell Value

From Dev

How to change value of one cell onchange of other cell value in DataGridview

From Dev

How to change cell value repeatedly by entering the value in other cell or sheet?

From Dev

DataTables, get value of hidden cell

From Dev

DataTables, get value of hidden cell

From Dev

How to change a cell's value in dataframe with pySpark?

From Dev

Handsontable : how to change cell value in render function

From Dev

How to change a formula according to cell value in excel?

From Dev

VBA : How to change the cell's value in a function?

From Dev

How to change a cell value periodically in libreoffice calc?

From Dev

How to change DataGrid cell background color based on cell value

From Dev

How change cell table color in php based on cell value?

From Dev

How to change datagrid cell value when user leaves cell

From Dev

How change cell table color in php based on cell value?

From Dev

DATA Table ... How to change the Color of cell as per the Cell Value Of Table

From Dev

How to change background color of cell based on other cell value by VBA

From Dev

Change Cell Value if There is Overflow

From Dev

Cell value change with Month

From Dev

Change value of cell in Javascript

From Dev

Datatables - How do I change background and text color of a cell changed dynamically?

From Dev

Get DataTables cell value to use in html link

From Dev

dataTables custom filtering of <tr> if cell contains value

From Dev

Change value in a cell based on value in another cell

From Dev

How to get the first row corresponding cell value if i change the other rows cell value in kendo child grid

Related Related

  1. 1

    How to change specific jQuery dataTables cell value

  2. 2

    How to change cell color of datatables?

  3. 3

    How to get value from dropdown in datatables cell

  4. 4

    How to get value from dropdown in datatables cell

  5. 5

    DataTables - How do I get/set the value of a cell in a row?

  6. 6

    How to Change Conditional Formatting of a Cell Based on a Change in the Cell Value

  7. 7

    How to change value of one cell onchange of other cell value in DataGridview

  8. 8

    How to change cell value repeatedly by entering the value in other cell or sheet?

  9. 9

    DataTables, get value of hidden cell

  10. 10

    DataTables, get value of hidden cell

  11. 11

    How to change a cell's value in dataframe with pySpark?

  12. 12

    Handsontable : how to change cell value in render function

  13. 13

    How to change a formula according to cell value in excel?

  14. 14

    VBA : How to change the cell's value in a function?

  15. 15

    How to change a cell value periodically in libreoffice calc?

  16. 16

    How to change DataGrid cell background color based on cell value

  17. 17

    How change cell table color in php based on cell value?

  18. 18

    How to change datagrid cell value when user leaves cell

  19. 19

    How change cell table color in php based on cell value?

  20. 20

    DATA Table ... How to change the Color of cell as per the Cell Value Of Table

  21. 21

    How to change background color of cell based on other cell value by VBA

  22. 22

    Change Cell Value if There is Overflow

  23. 23

    Cell value change with Month

  24. 24

    Change value of cell in Javascript

  25. 25

    Datatables - How do I change background and text color of a cell changed dynamically?

  26. 26

    Get DataTables cell value to use in html link

  27. 27

    dataTables custom filtering of <tr> if cell contains value

  28. 28

    Change value in a cell based on value in another cell

  29. 29

    How to get the first row corresponding cell value if i change the other rows cell value in kendo child grid

HotTag

Archive