Search code examples
javauser-interfacegwtextjsgxt

GXT 3.0 Grid widget search


I am working with the com.sencha.gxt(3.0) grid widget. I am trying to write a Java function that searches for a string in a row(across all columns) and only display the rows that contain this string. Is there a built in, or easy method in which I can do this?

Thanks


Solution

  • No.

    (I'm pretty sure you didn't actually mean to write a "yes or no" question...)


    In short, it would be silly for GXT to assume that all data in your grid is a string or string-like or only makes sense to compare in string-y ways. Plus, you might have all your data locally so it makes sense to do a simple filter on the client, or you might really be saying 'please search all ten million rows, on the server/db, and only send back the ones that match to render on the client.


    Client-side filtering

    The Store (probably a ListStore for a grid, or a TreeStore for the tree grid, but your question doesn't specify) has a built-in method for local filtering - you give it a function that takes an item (and some other possibly-relevant data), and returns true/false indicating whether or not the item should be hidden from the user. More than one filter can be applied, and if any filter says the item is hidden, then it is gone. In other words, this can be thought of as a sql where clause, where all statements are joined with and - if you want or, you can implement a filter that checks if any single filter wants the item visible.

    This filtering mechanism operates over the entire row item, the T in Store<T>. It doesn't know what a column is, since you could be using the store in any number of ways - items in a combobox, points on a chart, etc. It lets you build your own tools to perform the filtering. If your data is generalized in a way that makes it easy to know what all possible columns are, then you could easily write a loop over those columns that checks if any one of them contains the string, in which case return false so that the item is visible. Or, since you already built the ColumnModel full of ColumnConfigs, each of which has a ValueProvider and you know that it makes sense to compare each value with .toString().contains(queryText), you could iterate over the columns that way.


    Server-side filtering

    In this case, we have very little control on the client of what is happening, since you are very likely off-loading that work to your backend database. We still know the list of columns in the column model, but we either send a query for cells matching that text, or send a single query for the entire row. Either way, we modify the paging load config object that is being used, and send a new query for the data we want, and the actual work of doing the filtering is the server's job. It sounds like from your question that this is not what you want, but without a lot more detail, its hard to say for sure.