Skip to content

Conversation

@m1ga
Copy link
Contributor

@m1ga m1ga commented Oct 15, 2025

Will add searchText (like in ListView, took the code parts from those files) to the TableView so you can search for rows.

var win = Ti.UI.createWindow({
	extendSafeArea: false,
	layout: "vertical"
});

var buttons = Ti.UI.createView({
	height: Ti.UI.SIZE,
	layout: "vertical"
});

var btn2 = Ti.UI.createButton({
	title: 'search: hide0 (android, ios)',
});

buttons.add([btn2]);

btn2.addEventListener("click", function() {
	table.filterText = "";
	if (isVisible) {
		table.searchText = "hide0";
	} else {
		table.searchText = "";
	}
	isVisible = !isVisible
});

var tblSection = Ti.UI.createTableViewSection();
var addNumber = 0;
var rows = [];
var isVisible = true;
for (var i = 0; i < 50; ++i) {
	var row = Ti.UI.createTableViewRow({
		height: 50,
	})
	if (addNumber > 2) {
		addNumber = 0;
	}
	var lbl = Ti.UI.createTextField({
		value: "hide" + addNumber,
	});
	row.title = "hide" + addNumber
	row.add(lbl)
	tblSection.add(row);
	rows.push(row);
	addNumber++;
}

var table = Ti.UI.createTableView({
	data: [tblSection]
});

win.add(buttons);
win.add(table);
win.open();

@m1ga m1ga changed the title feat(android): add searchText to TableView feat(android): add searchText/filterText to TableView Oct 15, 2025
@m1ga
Copy link
Contributor Author

m1ga commented Oct 20, 2025

@hbugdoll maybe you have an idea here:

8a9789d#diff-091b65382eb52bdd5bea8e4e965d65b6e044cac879d9e10104ac7a68e18868a8R1605-R1616

I want to use table.searchText = "text" on iOS too. I've copied that part from the listview (like I did on Android) and it's building the index correctly (I've added a log here) and it only adds correct values but it is not updating the TableView data.

You can can the example from the first comment and click on the "search: hide0" button. It should only show "hide0" fields after that. But it is still showing all of them.

@hbugdoll
Copy link
Contributor

hbugdoll commented Nov 14, 2025

@m1ga It took me a while to understand this monster class (iphone/Classes/TiUITableView) 😮‍💨

You're right, the index is built correctly.
Concretely, in updateSearchResultIndexes the index searchResultIndexes is updated,
which is only used in indexPathFromSearchIndex: and numberOfRowsInSection:.
But only if isSearchStarted = YES and that requires [searchController isActive] = YES.

Currently, a Ti.UI.SearchBar is needed:

const searchBar = Ti.UI.createSearchBar();
const table = Ti.UI.createTableView({
	data: [tblSection],
	search: searchBar
});

@hbugdoll
Copy link
Contributor

hbugdoll commented Nov 14, 2025

Adding an additional check of searchString
in numberOfRowsInSection:, cellForRowAtIndexPath: and heightForRowAtIndexPath: works for me, see f992e59:

if ([self isSearchStarted] || self.searchString.length > 0) { ... }


Note: After setting table.searchText in the example, the first row with the buttons is of course hidden.
Placing the buttons outside the TableView makes it easier to test...

var win = Ti.UI.createWindow({
	extendSafeArea: false,
	layout: "vertical"
});

var buttons = Ti.UI.createView({
	height: Ti.UI.SIZE,
	layout: "vertical"
});

var btn = Ti.UI.createButton({
	title: 'filter: hide0',
});
var btn2 = Ti.UI.createButton({
	title: 'search: hide0',	
});
var btn3 = Ti.UI.createButton({
	title: 'filter: hide0, hide1',
});

buttons.add([btn, btn2, btn3]);

btn.addEventListener("click", function() {
	table.searchText = "";
	if (isVisible) {
		table.filterText = "hide0";
	} else {
		table.filterText = "";
	}
	isVisible = !isVisible
});
btn2.addEventListener("click", function() {
	table.filterText = "";
	if (isVisible) {
		table.searchText = "hide0";
	} else {
		table.searchText = "";
	}
	isVisible = !isVisible
});
btn3.addEventListener("click", function() {
	table.searchText = "";
	if (isVisible) {
		table.filterText = ["hide0", "hide1"];
	} else {
		table.filterText = [];
	}
	isVisible = !isVisible
});

var tblSection = Ti.UI.createTableViewSection();
var addNumber = 0;
var rows = [];
var isVisible = true;
for (var i = 0; i < 50; ++i) {
	var row = Ti.UI.createTableViewRow({
		height: 50,
	})
	addNumber++;
	if (addNumber > 2) {
		addNumber = 0;
	}
	var lbl = Ti.UI.createTextField({
		value: "hide" + addNumber,
	});
	row.title = "hide" + addNumber
	row.add(lbl)
	tblSection.add(row);
	rows.push(row);
}

var table = Ti.UI.createTableView({
	data: [tblSection]
});

win.add(buttons);
win.add(table);
win.open();
Simulator.Screen.Recording.-.iPhone.16e.-.2025-11-14.at.17.24.34.mov

@m1ga
Copy link
Contributor Author

m1ga commented Nov 15, 2025

Thank you for the feedback. Don't have my mac with me at the moment but I'll test it beginning of next week!

@m1ga m1ga changed the title feat(android): add searchText/filterText to TableView feat(all): add searchText to TableView Nov 20, 2025
@m1ga m1ga marked this pull request as ready for review November 20, 2025 11:00
@m1ga
Copy link
Contributor Author

m1ga commented Nov 20, 2025

Thanks again @hbugdoll ! Working fine. I've also updated the example in my first comment so it is using your code.

[searchView](Titanium.UI.TableView.searchView) property is set. Used in conjunction with
the [title](Titanium.UI.TableViewRow.title) property of the TableViewRow.
type: String
platforms: [android, iphone, ipad]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macos?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not tested that's why I didn't include it there. I don't have any setup to check it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants