Adding checkbox column to Category List

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 4 ans
Hi guys,
I'm writing a Widget plugin which trying to add one more column as the first column of Category datatable, in Category/List page, just like Product/List page, the first checkbox column.
I searched a lot, seems one easy solution is subscribe to ModelPreparedEvent and then write my own logic to add a new 'ColumnProperty'. I wrote a event handler but it's not working. I'm using Nop4.2. Thanks.

Here is my handleEvent code:

public void HandleEvent(ModelPreparedEvent<DataTablesModel> eventMessage)
        {
            if (eventMessage.Model.Name == "categories-grid")
            {
                eventMessage.Model.ColumnCollection.Insert(1, new ColumnProperty("Checkbox")
                {
                    IsMasterCheckBox = true,
                    Render = new RenderCheckBox("checkbox_categories"),
                    ClassName = NopColumnClassDefaults.CenterAll,
                    Width = "50"
                });
            }
        }
Il y a 4 ans
Hello
You need to delete selected categories then you have to add master check box.
how master check box add into data table, then you need to follow product list view page.
'ColumnCollection' in you have to add new 'ColumnProperty'
for e.g.
Go to => Admin =>Views =>  category => List.cshtml
add button for delete selected categories
<button type="button" id="delete-selected" class="btn bg-red">
                    <i class="fa fa-trash-o"></i>
                    @T("Admin.Common.Delete.Selected")
                </button>


new ColumnProperty(nameof(CategoryModel.Id))
                                {
                                    IsMasterCheckBox = true,
                                    Render = new RenderCheckBox("checkbox_categories"),
                                    ClassName =  NopColumnClassDefaults.CenterAll,
                                    Width = "50",
                                },


for selected categories to delete

$(document).ready(function () {
                                $('#delete-selected-action-confirmation-submit-button').bind('click', function () {
                                    var postData = {
                                        selectedIds: selectedIds
                                    };
                                    addAntiForgeryToken(postData);
                                    $.ajax({
                                        cache: false,
                                        type: "POST",
                                        url: "@(Url.Action("DeleteSelected", "Category"))",
                                        data: postData,
                                        error: function (jqXHR, textStatus, errorThrown) {
                                            $('#deleteSelectedFailed-info').text(errorThrown);
                                            $('#deleteSelectedFailed').click();
                                        },
                                        complete: function (jqXHR, textStatus) {
                                            updateTable('#categories-grid');
                                        }
                                    });
                                    $('#delete-selected-action-confirmation').modal('toggle');
                                    return false;
                                });
                            });

This is simple example for delete selected categories.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.