2013-06-25 70 views
1

我一直在研究如何使用jQuery動態構建網格。我已經閱讀了大量的API,並通過s.o進行了搜索。和谷歌,但似乎沒有人給它一個明確的整體立場。也許我只是不明白,所以我使用了一個名爲構建表的函數,我想返回結果。動態地使用jquery構建網格

所以一旦這個生成表按鈕被點擊,那麼它應該顯示網格。

但是沒有顯示

任何一個可以幫助

function buildTable(criteria) 
{ 
    var result = new Object(); 
    result.rows = criteria.rows; 
    result.totalRows = result.rows + 1; 
    result.row = new Array(); 
    for(var i = 0; i < result.rows; i++) 
    { 
    result.row[i] = new Object(); 
    result.row[i].shoeId = 100+i; 
    result.row[i].dressId = "LKM0" + i; 
    result.row[i].arrivalDt = "01/02/2013 15:45"; 
    result.row[i].stockDt = "01/02/2013 15:46"; 
    result.row[i].fashionStatus = "differences"; 
    } 
    return result; 
} 
</script> 



<input type="button" value="Generate a table." onclick=" document.getElementById('Grid').style.visibility = 'visible';" /> 

     <div class="Grid" id="Grid" onload="buildTable()" > </div> 
+0

建立表您是在客戶端還是服務器端生成數據? –

+0

我從服務器端生成數據db – bigsteve4288

回答

0

如果您正在生成服務器端的數據,你既可以使它在渲染頁面到您的網格:

<div id="Grid" style="display:none"> 
    <table> 
     ... etc ... 
    </table> 
</div> 

,然後只顯示DIV當他們點擊按鈕

或者如果你只需要建立表時,他們按一下按鈕,那麼你可以做這樣使用Ajax:

<input type="button" value="Generate a table." onclick="loadGrid()" /> 

<script> 
    $("#Grid").load("Url to generate table", function() { 
     $(this).show(); 
    }); 
</script> 

或者,如果你真的想使用JavaScript,然後this might give you some ideas

+0

感謝Martin,我將試試這種方式。謝謝你的建議 – bigsteve4288