TurboGears - DataGrid

ToscaWidgets में डेटाग्रिड नियंत्रण होता है जो डेटा को सारणीबद्ध रूप में प्रस्तुत करने का एक त्वरित तरीका प्रदान करता है। DataGrid ऑब्जेक्ट निम्नानुसार घोषित किया गया है -

from tw2.forms import DataGrid
student_grid = DataGrid(fields = [('Name', 'name'),('City', 'city'),
   ('Address','address'), ('PINCODE', 'pincode')])

अब, showgrid () फ़ंक्शन स्टूडेंट टेबल के सभी रिकॉर्ड्स को पुनः प्राप्त करता है और ग्रिड.html टेम्प्लेट में डेटा को उजागर करता है। पहले showgrid () फ़ंक्शन के लिए कोड और फिर ग्रिड। Html कोड नीचे दिया गया है -

ग्रिड दिखाएं()

@expose('hello.templates.grid')
def showgrid(self):
   data = DBSession.query(student).all()
   return dict(page = 'grid', grid = student_grid, data = data)

grid.html

<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml"
   xmlns:py = "http://genshi.edgewall.org/"
   lang = "en">
   
   <head>
      <title>Student Registration Form</title>
   </head>
   
   <body>
      <div id = "getting_started">
         <div>${grid.display(value = data)}</div>
      </div>
   </body>

</html>

निम्न सारणीबद्ध डेटा कब प्रदर्शित किया जाएगा http://localhost:8080/showlist URL ब्राउज़र में दर्ज किया गया है -