Angularjs表格中没有数据可用

时间:2017-06-28 01:15:10

标签: angularjs angular-datatables

我正在使用angularjs数据表,每次在呈现表之前我都会收到“表中没有数据”消息。在消息之后,表格以预期的方式显示数据。那么如何解决问题? 检查demo

<?php

$list = [ 'abc',
      '{a}',
      '*',
      '{*}',
      '{abc',
      '}a',
    ]; // An array of strings to sort

$customOrderPrioritized = ['{','*','}']; // Add any characters here to prioritize them, in the order they appear in this array

function ustrcmp($a, $b, $customOrderPrioritized) {
    if ($a === $b) return -1; // same, doesn't matter who goes first

    $n = min(strlen($a), strlen($b)); // compare up to the length of the shortest string
    for ($i = 0; $i < $n; $i++) {
        if ($a[$i] === $b[$i]) continue; // matching character, continue to compare next

        $a_prio = in_array($a[$i], $customOrderPrioritized);
        $b_prio = in_array($b[$i], $customOrderPrioritized);

        // If either one has a prioritized char...
        if ($a_prio || $b_prio) {
            if ($a_prio && $b_prio) {
                // Both are prioritized, check which one is first...
                return array_search($a[$i], $customOrderPrioritized) <= array_search($b[$i], $customOrderPrioritized) ? -1 : 1;
            } elseif ($a_prio) {
                return -1; // a < b
            } else { // must be $b_prio
                return +1; // b > a
            }
        }
        return strcmp($a[i], $b[$i]); // compare single character
    }
    // if they have identical beginning, shortest should be first
    return strlen($a) <= strlen($b) ? -1 : +1;
}

usort(
    $list, 
    function($a, $b) use ($customOrderPrioritized){
        return ustrcmp($a, $b, $customOrderPrioritized);        
    }
); // run custom comparison function, pass in $customOrderPrioritized (or make it global)

print_r($list); // print the list

/* The sorted array should look like:
Array
(
    [0] => {*}
    [1] => {a}
    [2] => {abc
    [3] => *
    [4] => }a
    [5] => abc
)
*/

2 个答案:

答案 0 :(得分:5)

表在数据从服务器返回之前呈现。您可能希望在其中一个HTML元素上使用ng-if等待数据可用:

<table ng-if="userList" datatable="ng">

修改您不喜欢的邮件的CSS类为dataTables_empty。所以,如果两个数据都已加载且表中没有显示任何行,那么你可能只能用CSS显示它。

答案 1 :(得分:0)

这对我来说是工作,在从服务器返回数据之前正在渲染表。您可能要使用

<table class="table table-bordered" *ngIf="mynotes" datatable [dtOptions]="dtOptions">