Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table not displaying new rows #1426

Closed
JasonWeiseUnreal opened this issue Oct 10, 2019 · 11 comments
Closed

Table not displaying new rows #1426

JasonWeiseUnreal opened this issue Oct 10, 2019 · 11 comments

Comments

@JasonWeiseUnreal
Copy link

I am using Metro-UI table (data-role="table") and have found if I add rows dynamically the table does not display the new rows.
If I bring it back to a normal table (without data-role="table") then the new rows display fine.

Essentially I am adding the rows like this:

        <table class="table striped table-border row-border" data-role="table" data-rows="5">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Book Name</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var book in BookList)
                {
                    <tr>
                        <td>@book.Id</td>
                        <td>@book.Name</td>                       
                    </tr>
                }
            </tbody>
        </table>

Is there a way to force the table to redraw after I add a row (i.e. add a new book to BookList)
I am guessing it is because in the background the Metro-UI table is being refreshed / managed by the Metro-UI JavaScript that seems to ignore the new rows once the table is initially created.

In the case of just a normal <table></table> then it just redraws each time I add a row...

In essence I am just looking for a way for the table to refresh / redraw.

Thanks in advance.

@olton
Copy link
Owner

olton commented Oct 10, 2019

in the current version, the table does not support the dynamic addition of rows

@JasonWeiseUnreal
Copy link
Author

@olton thanks for the speedy reply, that is a shame though.
I will have to see if I can work around it.

I appreciate you taking the time to answer.

@olton
Copy link
Owner

olton commented Oct 10, 2019

I do not consider my work a shame!

@olton olton closed this as completed Oct 10, 2019
@olton
Copy link
Owner

olton commented Oct 10, 2019

New in 4.3.2

var row = ['book_id', 'book_name'];
var redraw = true;
var table = Metro.getPlugin('el', 'table');
table.addItem(row, redraw);

or

var rows = [
    ['book_id_1', 'book_name'], 
    ['book_id_2', 'book_name']
];
var redraw = true;
var table = Metro.getPlugin('el', 'table');
table.addItems(rows, redraw);

@olton olton reopened this Oct 10, 2019
@olton olton added this to the 4.3.2 milestone Oct 10, 2019
@olton olton closed this as completed Oct 20, 2019
@alefab
Copy link

alefab commented Oct 23, 2019

Hello, sorry to ask but in the sample
var table = Metro.getPlugin('el', 'table');
What are supposed to be 'el' and 'table' ?

@olton
Copy link
Owner

olton commented Oct 23, 2019

el - table selector, table - constant, identifies which role to use to get the plugin. Example:

<table data-role="table" id="table1">...</table>
-------------------------------------------------------
var tbl = Metro.getPlugin('#table1', 'table');

now tbl contains component table, and you can use component API

@alefab
Copy link

alefab commented Oct 23, 2019

Thanks, it's working now. Is there a way to fully clean the rows of the table also ?
I have tried to look at the source near addItem() but don't find any revelant method to do it.

@olton
Copy link
Owner

olton commented Oct 23, 2019

Hack

function clearTable() {
    var table = Metro.getPlugin("#t1", "table");
    table.items = [];
    table.draw();
}

@alefab
Copy link

alefab commented Oct 23, 2019

Thanks again, working perfectly.

olton added a commit that referenced this issue Oct 23, 2019
@olton
Copy link
Owner

olton commented Oct 23, 2019

I added method clear() in 4.3.3

@olton
Copy link
Owner

olton commented Oct 23, 2019

In 4.3.3 to clear table you can call the method clear:

var table = Metro.getPlugin(...)
table.clear();

olton added a commit that referenced this issue Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants