morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
204 stars 64 forks source link

Bulk operations? #76

Closed saileshkush95 closed 2 years ago

saileshkush95 commented 2 years ago

Thanks for this amazing package. I want to remove detail page button and add checkbox for the bulk task like delete. I didn't find any method to disable detail page button'

morlandi commented 2 years ago

Hello @saileshkush95

Detail page button is disabled (more precisely: not present at all) by default. That is, unless you add explicitly AjaxDatatableView.render_row_tools_column_def() to column_defs in your AjaxDatatableView. If you did, try to remove it.

To add a checkbox for bulk task, you could try something similar to the snippet below, where an "Edit" button is added to each table row for demonstration purposes.

This code is part of the example project: https://github.com/morlandi/django-ajax-datatable/blob/master/example/frontend/ajax_datatable_views.py

and published on the demo site:

http://django-ajax-datatable-demo.brainstorm.it/tracks/

class ArtistAjaxDatatableView(AjaxDatatableView):

    model = Artist
    code = 'artist'
    title = _('Artist')
    initial_order = [["name", "asc"], ]
    length_menu = [[10, 20, 50, 100, -1], [10, 20, 50, 100, 'all']]
    search_values_separator = '+'
    show_date_filters = False

    column_defs = [
        AjaxDatatableView.render_row_tools_column_def(),
        {'name': 'pk', 'visible': False, },
        {'name': 'name', 'visible': True, },
        {'name': 'edit', 'title': 'Edit', 'searchable': False, 'orderable': False, },
    ]

    def customize_row(self, row, obj):
        row['edit'] = """
            <a href="#" class="btn btn-info btn-edit"
               onclick="var id=this.closest('tr').id.substr(4); alert('Editing Artist: ' + id); return false;">
               Edit
            </a>
        """
Screenshot 2022-01-17 at 19 30 20