Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add context menu to datatables 1.10?

I'm using DataTables (datatables.net) and I would like to add a context menu to my table.

I found jQuery contextMenu and also description in the DataTables forum on how somebody implemented the context menu. But it seems that at least the DataTables I'm currently using (1.10) has evolved quite much. I have not information about the Context Menu plugin. (meaning what version was using in this forum post and what I have downloaded).

If I use it as described in the forum post and adapt it to 1.10 (to my humble knowledge) I'm comming to this

var myTable = $("#myTable ").DataTable( {
    "drawCallback": function( settings ) {
        $("#myTable tbody tr").contextMenu(
        {
            menu: 'myMenu'},
            function( action, el, pos ) {
                var aData = myTable.GetData( el.context );
            }
        );
    }
} );

But executing this code will give me this error:

Uncaught Error: No selector specified in jquery.contextMenu.js:1273

Has anybody recently implementet context menu to DataTable 1.10?

like image 691
thowa Avatar asked May 17 '14 11:05

thowa


1 Answers

I have just see this question, and would like to answer it because I was looking for a solution for this.

Here you have a demo using jquery.ui-contextmenu: DEMO

I use jquery.ui in addition, hope this won't be a problem for you.

It is integrated with functions fnFilter() and fnFilterClear(), so you can filter data using right-click.

Thanks!

UPDATE: DataTables 1.10 API style!

Removed fnFilter() and fnFilterClear() and use the new search() API method.

DEMO :)

like image 110
alesnav Avatar answered Nov 07 '22 18:11

alesnav