2016-09-12 13 views
0

我有一個網頁組在這裏的列表:如何使兩行顯示爲一個使用DataTables?

http://liquidchurch.com/groups/groups-browse/

它使用WordPress,數據表和建信核心API插件和行之有效的。

我需要爲每個組添加一個描述,但描述太長以至於無法添加到表的末尾,所以我想讓它出現在單獨的行中,但仍然「附加」到在視覺外觀和分類目的上的主要行(關於該組)。

這裏是我當前的代碼:

https://gist.github.com/davidshq/2c54fae1d3fd73bc6eda7dc537c1abed

+2

看一看https://datatables.net/examples/api/row_details.html –

+0

謝謝,我確實看過這個......我仍然對這是如何工作的有點困惑......很想找到一篇關於它的更詳細的文章。 – davemackey

回答

0
// set up the datatablse 
    var table = $('#example').DataTable(); 

    // list of descriptions for each person 
    var desc = { 
     "Ashton Cox": "Ashton is a baller", 
     "Cedric Kelly": "Died in the last harry potter movie", 
     "Garrett Winters": "this guy is cold af" 
    }; 

    // loop each row 
    $('#example tbody').find("tr").each(function(){ 

     // get the name which matches the keys in our 
     // descriptions, in this case it's in the first col 
     var name = $(this).find("td").eq(0).text(); 
     if(!name.length) return; 

     if(undefined === desc[name]) return; 
     table.row($(this)).child(desc[name]).show(); 

    }); 

演示:https://jsfiddle.net/j767gs8t/1

+0

謝謝,問題是我從通過第三方CCB API創建的自定義帖子類型中提取數據。我通過WP_Query得到這個,看我的要點(原始問題鏈接) – davemackey

相關問題