SlideShare uma empresa Scribd logo
1 de 5
Baixar para ler offline
ce nade p.o rg

http://www.cenadep.o rg/2013/12/09/membuat-filter-data-dengan-delphi-dan-dbgrideh/

Membuat Filter Data Dengan Delphi dan DBGridEh

Selain mumpuni untuk menampilkan data dalam bentuk treeview di Delphi, DBGridEh juga mendukung
f ilter data seperti gambar di atas.
Yang perlu diperhatikan dalam membuat f ilter data dbgrid seperti di atas adalah – sesuai dokumentasi
EhLibrary – T DBGridEh harus dihubungkan dengan T MemTableEh sebagai sumber data. Kenapa bukan ke
dataset langsung seperti Z Query, ADOTable atau ADOQuery saja? Karena dengan T MemTableEh data
dapat dicache ke memori sehingga akses data dan f iltering dapat dilakukan dengan cepat dibandingkan
f iltering yang diterapkan ke dataset yang terhubung langsung ke database.

Membuat Akses Dat a Dari Dat abase
Silahkan buat sebuah projek baru di Delphi.
Ingat, pastian Anda sudah menginstall EhLibrary di Delphi Anda. Sedangkan untuk akses database, saya
menggunakan MyDac dan MySQL, tapi tentu Anda dapat menggunakan koneksi apapun yang Anda suka.
Boleh Z eos, ADO, atau Interbase Express.
Lanjut, tambahkan sebuah komponen koneksi data dan sebuah komponen query ke f orm. Saya
menggunakan T MyConnection dan T MyQuery. Silahkan sesuaikan. Lalu tambahkan pula sebuah T Button
untuk me-ref resh data, beri caption Ref resh. Plus juga sebuah T DBgridEh ditambahkan ke f orm tapi jangan
di-set dulu property Datasource-nya.
Atur property Connection dari komponen query ke komponen koneksi (saya menghubungkan
MyQuery1.Connection ke MyConnection1), lalu atur property komponen koneksi agar terhubung ke
database.
Sebagai perbandingan, lihat gambar hasil desain saya:
Setelah koneksi database berhasil, atur property komponen query, isikan property SQL untuk mengakses
data kemudian set roperty Active ke True untuk memastikan bahwa data telah di-load dengan benar.
Sudah? Lanjut. Tambahkan sebuah komponen T MemTableEh dan sebuah T DataSource. Hubungkan
Datasource ke MemTableEh tadi. Hubungkan juga DBGridEh dengan DataSource
Sekarang kita akan mengaktif kan MemTableEh sebagai dataset cache (penyimpanan data sementara)
sekaligus penghubung antara komponen query (MyQuery) dan DBGridEh. Klik kanan pada komponen
MemTableEh, klik Assign Local Data…
… dan pilih MyQuery1 (sesuaikan dengan komponen query/table yang Anda
gunakan).
Sekarang data akan di-load dari query dan ditampung di MemTableEh,
sehingga tampil di DBgridEh:
Anda dapat membuang kolom-kolom yang diperlukan dari DBGridEh dengan klik kanan pada DBGridEh dan
klik Columns Editor…

Mengakt if kan Filt er Dat a Di DbGridEh
Klik DBGridEh dan lihat property ST Filter. Atur property Visible ke True, property Local ke True dan property
InstantApply ke True.
Perhatikan gambar berikut:
Sharing is Sexy!
Benar! Sharing itu berusia 20 tahun, semester 4 di FK UI!

Dari property di atas, tampilan DBGridEh akan berubah menjadi:
Seperti terlihat di gambar, kolom-kolom untuk f ilter data sudah ada. Tapi belum berf ungsi dengan baik.
Sekarang pindah ke Code Editor dengan menekan tombol F12. Di source code, bagian uses, tambahkan
unit EhLibMT E seperti gambar berikut:

Mengakt if kan But t on Ref esh Dat a
Karena data berada di cache MemTableEh, me-ref resh data dari database dengan MyQuery1.Refresh
tidak akan me-ref resh data yang tampil di DBGridEh, shingga data dalam cache-lah yang harus di-load ulang
dari MyQuery1.
Klik ganda Button ref resh dan isikan kode seperti berikut:
0001
0002
0003
0004
0005

procedure TForm1.But t on1Click(Sender: TObject );
begin
MyQuery1.Refresh;
MemTableEh1.LoadFromDat aSet (MyQuery1, -1 , lmCopy,false);
end;

Sekarang Anda sudah dapat menjalankan projek dan menguji f ilter yang ada…

Demikian tutorial kali ini, semoga bermanf aat.
Selamat mencoba.

Mais conteúdo relacionado

Destaque

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Destaque (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Cenadep.org - Membuat Filter Data DBgrid Dengan Delphi dan DBGridEh

  • 1. ce nade p.o rg http://www.cenadep.o rg/2013/12/09/membuat-filter-data-dengan-delphi-dan-dbgrideh/ Membuat Filter Data Dengan Delphi dan DBGridEh Selain mumpuni untuk menampilkan data dalam bentuk treeview di Delphi, DBGridEh juga mendukung f ilter data seperti gambar di atas. Yang perlu diperhatikan dalam membuat f ilter data dbgrid seperti di atas adalah – sesuai dokumentasi EhLibrary – T DBGridEh harus dihubungkan dengan T MemTableEh sebagai sumber data. Kenapa bukan ke dataset langsung seperti Z Query, ADOTable atau ADOQuery saja? Karena dengan T MemTableEh data dapat dicache ke memori sehingga akses data dan f iltering dapat dilakukan dengan cepat dibandingkan f iltering yang diterapkan ke dataset yang terhubung langsung ke database. Membuat Akses Dat a Dari Dat abase Silahkan buat sebuah projek baru di Delphi. Ingat, pastian Anda sudah menginstall EhLibrary di Delphi Anda. Sedangkan untuk akses database, saya menggunakan MyDac dan MySQL, tapi tentu Anda dapat menggunakan koneksi apapun yang Anda suka. Boleh Z eos, ADO, atau Interbase Express. Lanjut, tambahkan sebuah komponen koneksi data dan sebuah komponen query ke f orm. Saya menggunakan T MyConnection dan T MyQuery. Silahkan sesuaikan. Lalu tambahkan pula sebuah T Button untuk me-ref resh data, beri caption Ref resh. Plus juga sebuah T DBgridEh ditambahkan ke f orm tapi jangan di-set dulu property Datasource-nya. Atur property Connection dari komponen query ke komponen koneksi (saya menghubungkan MyQuery1.Connection ke MyConnection1), lalu atur property komponen koneksi agar terhubung ke database. Sebagai perbandingan, lihat gambar hasil desain saya:
  • 2. Setelah koneksi database berhasil, atur property komponen query, isikan property SQL untuk mengakses data kemudian set roperty Active ke True untuk memastikan bahwa data telah di-load dengan benar. Sudah? Lanjut. Tambahkan sebuah komponen T MemTableEh dan sebuah T DataSource. Hubungkan Datasource ke MemTableEh tadi. Hubungkan juga DBGridEh dengan DataSource Sekarang kita akan mengaktif kan MemTableEh sebagai dataset cache (penyimpanan data sementara) sekaligus penghubung antara komponen query (MyQuery) dan DBGridEh. Klik kanan pada komponen MemTableEh, klik Assign Local Data… … dan pilih MyQuery1 (sesuaikan dengan komponen query/table yang Anda gunakan). Sekarang data akan di-load dari query dan ditampung di MemTableEh, sehingga tampil di DBgridEh:
  • 3. Anda dapat membuang kolom-kolom yang diperlukan dari DBGridEh dengan klik kanan pada DBGridEh dan klik Columns Editor… Mengakt if kan Filt er Dat a Di DbGridEh Klik DBGridEh dan lihat property ST Filter. Atur property Visible ke True, property Local ke True dan property InstantApply ke True. Perhatikan gambar berikut: Sharing is Sexy! Benar! Sharing itu berusia 20 tahun, semester 4 di FK UI! Dari property di atas, tampilan DBGridEh akan berubah menjadi:
  • 4. Seperti terlihat di gambar, kolom-kolom untuk f ilter data sudah ada. Tapi belum berf ungsi dengan baik. Sekarang pindah ke Code Editor dengan menekan tombol F12. Di source code, bagian uses, tambahkan unit EhLibMT E seperti gambar berikut: Mengakt if kan But t on Ref esh Dat a Karena data berada di cache MemTableEh, me-ref resh data dari database dengan MyQuery1.Refresh tidak akan me-ref resh data yang tampil di DBGridEh, shingga data dalam cache-lah yang harus di-load ulang dari MyQuery1. Klik ganda Button ref resh dan isikan kode seperti berikut:
  • 5. 0001 0002 0003 0004 0005 procedure TForm1.But t on1Click(Sender: TObject ); begin MyQuery1.Refresh; MemTableEh1.LoadFromDat aSet (MyQuery1, -1 , lmCopy,false); end; Sekarang Anda sudah dapat menjalankan projek dan menguji f ilter yang ada… Demikian tutorial kali ini, semoga bermanf aat. Selamat mencoba.