JavaFX TableView with Search Filter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome in Gulati health guys this is the new Java effects tutorial for you so in this tutorial we will see the implementation of search filter on table view before starting guys I have a request if you think this video is useful for you so please like this video and share with your friends as well and please subscribe my channel and press the notification bar icon if you want the latest video updates from my channel and now let's get it started so guys this is the Java effects ml based project I have created this project in the dead beans ID and I have implemented the search filter on the table view so this search is implemented only on three columns named department' and salary' and we have a choice we can perform the search on the all columns of the table view so I will show you all the things inside the code first I will show you a small demo what kind of search we are performing and how is it working now you can see I have just typed one string wrodar and the matching is found inside the department table and that record is written okay and now I'm going to type the name of a one person Peter so the Peter is found inside the name that means the matching string is found in this okay so we have implemented the search on all table columns so the logic is going like this way you can search your string in any of your table view column okay but we have to write the code to search for all column okay so I haven't show you the place where you have to write this code and I am going to search the Selvi okay so you can see the salary is 30,000 so this is found inside the salary column that means whatever this thing I have typed here that is going to be searched in the defined columns and the matching record will be written inside the tableview suppose you are searching one keyword like dream okay so the no matching record is found and the empty list is returned and set into the table view so no record will be displayed inside the table view so guys this is the working of a search for it on the table view now we will see the implementation logic behind the scene so I'm going to close this one and I will show you first this diagram this is a very simple diagram so the core component we are using to perform search is filtered list class okay so we have to just create a filtered list class object and we have to pass our data list that means whatever the data we have set inside the table view so we have to pass that list inside the constructor of filter list class okay then we have to set a search text field and we have to add a listener and we have to connect this with the filter list class okay so every time when you are going to type anything in this search box that will act as a predicate and this predicate is going to be searched inside the data list that means whatever the table data okay and if any matching string is found in any of the column so that record will be written and that will be set inside the table so that is this is the very simple thing now we are going to see the code so first I will show you the effects ml okay so here's the effects ml what we have done in the effects ml part so this is the search box so we have assigned effects ID to this one and we have our table view with the effects added table view and the column employee ID name email ID department' and salary' also has FX ID you can see here okay so we have done only this thing on this F XML cocaine are we going inside the controller file so here is our controller file and we will start from the beginning so this is the added effect similar notation to use the defined objects on the effects ml so the FX ID of the text field FX idea of table view and these are the FX ID for the columns okay and we are using employee class as a data model so this is our employee class this is very simple we have five properties for five column values and we have one constructor and we have a getter and setter method for all these five properties okay now going back inside the controller and we have to prepare some data to set inside the table views so we have to create one of the rebel lists of type employee okay and we will collect the employee object inside data list and then we will pass this data list to the filtered list class okay and now we are going inside initialize this is a very simple and regular bug if we are working on the table view so we have to associate the data model property value to the column so you have to use set cell value factory method to do that so I have applied the sets 11 factory method on each column ok and now here in these lines we have created the simple employee object and then we have added inside the data list ok now the core logic is going to be started at this place so we have created the filtered list class ok and we have just passed our data list that we have prepared in the previous step okay now we are going to associate the listener with the search text field so this is the effects ID or the search text field you can say that this is the object with the help of text property method we are adding the listener and this is the default values that we will get the implementation of filter list class okay and here we have a filter list class object okay and we are setting the predicate so that means whatever you are going to type that will be passed to the filter list class and the filtered list class implementation will search the values inside the column okay and the next code is for looking the value if you have not typing anything that means the new typing value is null and this is empty then we will return true that means the meaning of this true means we are returning the empty list okay we are returning - that means you have not typed anything anything so no search will be performed and the data will be remain as it is okay so initially we have added the five employer object so that will remain same instead of table view now if we're going to perform search so we have to first fetch the text value we have entered some text value inside the search box so it will be collected here in this variable and then this is the logic where we are performing our search so we have entered this string value and we are going to look this is string value inside the first column so this is the default variable okay and we are getting a employee name with the help of this property method employed odd cat first name let me show you okay we are getting here so it will return the employee name and we are converting it to the lower case then we are comparing the index if it is found that means that matching recount is found then the logic will return the matching row inside the table view okay so we are performing sequential search so first we are looking the input string inside the first column and then we are going to search inside the department and then we are going to search inside the salary column and if you want to add more search column so you can add your code at this place okay with the if-else pattern so this is the main place where you can add more columns to perform the search and in the last once we will get this filtered data okay so that will be sorted out with the help of this sorted list class and finally it will be said inside the table view with the help of set items method this is very simple thing at line number 96 we just added this order data okay so we have wrapped up our observable list inside this filtered list okay so this filter list class is performing all the search functionality and whatever the implementation inside that will return you the filter these search records okay if matching record falls then it will return you the matching record if no record will found so the table view will be empty and guys again I am going to run this project one more time okay here we go you can see and I am going to search the string bat and this string is not found so the empty list is written and set inside the table view okay guys so this is the way if you want to explore explore more so you can put the debug point on the code and you can look into more I have just given you a simple idea how you can use the search box for your easiness I I have given the download link of this sample project so you guys can download and import in your NetBeans IDE and you can explore more and guys if you have any doubts so please comment in the comment box I will try my best to reply as soon as possible and guys please like and share this video with your friends as well so that you also can take the benefit of this tutorial and subscribe my channel and press the notification by like a so you will get the latest video updates ASAP and guys thanks for watching cool ID help
Info
Channel: Cool IT Help
Views: 23,928
Rating: undefined out of 5
Keywords: javafx, tableview, javafx tableview with search filter, how to use search on tableview in javafx, Search TableView list in JavaFX, JavaFX 8 TableView Sorting and Filtering, How to add a filter search to a table list on JavaFX, JavaFX TableView filter, javafx tutorial for beginners
Id: FeTrcNBVWtg
Channel Id: undefined
Length: 11min 45sec (705 seconds)
Published: Thu Jul 18 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.