Getting last row duplicated

Getting last row duplicated

ankur2128ankur2128 Posts: 4Questions: 1Answers: 0

Hello,

I am using .NET DataView to generate a table and initialize it. Then I have couple of controls for filtering. I use DataView.RowFilter that gives me correct data. However, when I try to refresh it, I got an error that it cannot initialize.

I found the solutions to that problem (I am not sure if this is causing me trouble) I added "destroy": true while initializing.

Now that error message goes away. However, I get the last row duplicated the number of times I filter the records.

Any help is much appreciated.

Thanks,
Ankur

Answers

  • ankur2128ankur2128 Posts: 4Questions: 1Answers: 0

    The error I got before was "Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3"

    To fix that I added the below in initialization

    "retrieve": true,

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    I'm not sure why you'd get that duplication, unless there's code that's modifying the table in the DOM.

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • ankur2128ankur2128 Posts: 4Questions: 1Answers: 0
    edited December 2019

    Hello @collin

    Thanks for your response. I am not sure if I can add the Blazor code there.

    I have a Blazor code that creates the table element.

     <div style="overflow-x:scroll;">
            <table id="report" class="cell-border stripe">
                <thead>
                    <tr id="filterControlRow">
                        @for (int i = 0; i < ReportData.Table.Columns.Count; i++)
                        {
    

    ...
    Using that id I call the JS for initializing it

     $(document).ready(function () {
                    $('#' + tableId).dataTable()
                    var table = $('#' + tableId).DataTable(
                        {
                            
                            "info": false,
                            "order": [[0, "asc"]],
                            "scrollX": true,
                            "autoWidth": false,
                            "pagingType": "full_numbers",
                            "searching": false,
                            "lengthMenu": [[10, 50, 200, 1000, -1], [10, 50, 200, 1000, "All"]],
                            dom: 'B<"clear">lfrtip',
                            buttons: {
                                name: 'primary',
                                buttons: ['pdf', 'excel']
                            }
                        }
    
                    );
                    
                });
    

    I have to add custom controls for filtering which I added in the <thead> section of the same table.

    Added a button to filter the records. Blazor is returning me correct number of rows that need to be displayed.

    But I am unable to get that updated data hooked back to it. Initially i got an error **Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
    **

    Then I added the "retrieve":true in the initialization.

    Also I have another drop down to show different reports.

    I hope this makes sense.

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Then I added the "retrieve":true in the initialization.

    That flag is used to indicate that you acknowledge you understand that the table won't be initialised again and all you want to do is get the API instance. I'd say that is not what you intend here.

    Before you do the Blazor refresh, you need to destroy the old table (destroy()). What is the code that is used to trigger the Blazor refresh (I should note that neither Colin nor I have used Blazor before...)

    Allan

  • ankur2128ankur2128 Posts: 4Questions: 1Answers: 0
    edited December 2019

    Thanks @allan and @collin. Also I noted that DataTable is not working in Microsft Edge.

    You can look at the code and its working in Chrome but not working in Edge browser here.

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    DataTables works fine in Edge, try this example here.

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.