Search input appears empty with ListView
I'm trying to build a listView with a search bar, but it seems that the input value of the search bar doesn't get inserted and tested against available results.
Instead it return an empty text: [ ]
.
I've even made an empty array id: 5, text: " ", text2: "test"
and this also doesn't return any results..
I'm now wondering why does my search bar return empty?
The value of the input this.state.searchText
does get checked in the for loop
against any results.
for (i = 0; i < textLength; i++)
if (aText[i].text === searchText)
console.log("found: " + aText[i].text);
return aText[i];
I'm still learning, have I approached this wrong? Should I have used an object instead of an array?
And how come I don't get any results?
I've made an example app so you can see the code in an working environment.
Any kind of advice, feedback or criticism is more than welcome.
full example code
import React, Component from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
// Row comparison function
const rowHasChanged = (r1, r2) => r1.id !== r2.id;
// DataSource template object
const ds = new ListView.DataSource( rowHasChanged );
export default class App extends Component
state =
dataSource: ds.cloneWithRows(rows),
rows
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const aText = this.state.rows;
const filteredTexts = this.state.rows.filter(checkText);
console.log("text: " + JSON.stringify(filteredTexts));
function checkText()
var i;
for (i = 0; i < textLength; i++)
if (aText[i].text === searchText)
console.log("found: " + aText[i].text);
return aText[i];
this.setState(
searchText,
dataSource: this.state.dataSource.cloneWithRows(filteredTexts)
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.text
rowData.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<ListView
style=styles.container
dataSource=this.state.dataSource
renderRow=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
container:
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue"
);
AppRegistry.registerComponent("App", () => App);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
reactjs react-native
add a comment |
I'm trying to build a listView with a search bar, but it seems that the input value of the search bar doesn't get inserted and tested against available results.
Instead it return an empty text: [ ]
.
I've even made an empty array id: 5, text: " ", text2: "test"
and this also doesn't return any results..
I'm now wondering why does my search bar return empty?
The value of the input this.state.searchText
does get checked in the for loop
against any results.
for (i = 0; i < textLength; i++)
if (aText[i].text === searchText)
console.log("found: " + aText[i].text);
return aText[i];
I'm still learning, have I approached this wrong? Should I have used an object instead of an array?
And how come I don't get any results?
I've made an example app so you can see the code in an working environment.
Any kind of advice, feedback or criticism is more than welcome.
full example code
import React, Component from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
// Row comparison function
const rowHasChanged = (r1, r2) => r1.id !== r2.id;
// DataSource template object
const ds = new ListView.DataSource( rowHasChanged );
export default class App extends Component
state =
dataSource: ds.cloneWithRows(rows),
rows
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const aText = this.state.rows;
const filteredTexts = this.state.rows.filter(checkText);
console.log("text: " + JSON.stringify(filteredTexts));
function checkText()
var i;
for (i = 0; i < textLength; i++)
if (aText[i].text === searchText)
console.log("found: " + aText[i].text);
return aText[i];
this.setState(
searchText,
dataSource: this.state.dataSource.cloneWithRows(filteredTexts)
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.text
rowData.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<ListView
style=styles.container
dataSource=this.state.dataSource
renderRow=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
container:
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue"
);
AppRegistry.registerComponent("App", () => App);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
reactjs react-native
add a comment |
I'm trying to build a listView with a search bar, but it seems that the input value of the search bar doesn't get inserted and tested against available results.
Instead it return an empty text: [ ]
.
I've even made an empty array id: 5, text: " ", text2: "test"
and this also doesn't return any results..
I'm now wondering why does my search bar return empty?
The value of the input this.state.searchText
does get checked in the for loop
against any results.
for (i = 0; i < textLength; i++)
if (aText[i].text === searchText)
console.log("found: " + aText[i].text);
return aText[i];
I'm still learning, have I approached this wrong? Should I have used an object instead of an array?
And how come I don't get any results?
I've made an example app so you can see the code in an working environment.
Any kind of advice, feedback or criticism is more than welcome.
full example code
import React, Component from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
// Row comparison function
const rowHasChanged = (r1, r2) => r1.id !== r2.id;
// DataSource template object
const ds = new ListView.DataSource( rowHasChanged );
export default class App extends Component
state =
dataSource: ds.cloneWithRows(rows),
rows
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const aText = this.state.rows;
const filteredTexts = this.state.rows.filter(checkText);
console.log("text: " + JSON.stringify(filteredTexts));
function checkText()
var i;
for (i = 0; i < textLength; i++)
if (aText[i].text === searchText)
console.log("found: " + aText[i].text);
return aText[i];
this.setState(
searchText,
dataSource: this.state.dataSource.cloneWithRows(filteredTexts)
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.text
rowData.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<ListView
style=styles.container
dataSource=this.state.dataSource
renderRow=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
container:
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue"
);
AppRegistry.registerComponent("App", () => App);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
reactjs react-native
I'm trying to build a listView with a search bar, but it seems that the input value of the search bar doesn't get inserted and tested against available results.
Instead it return an empty text: [ ]
.
I've even made an empty array id: 5, text: " ", text2: "test"
and this also doesn't return any results..
I'm now wondering why does my search bar return empty?
The value of the input this.state.searchText
does get checked in the for loop
against any results.
for (i = 0; i < textLength; i++)
if (aText[i].text === searchText)
console.log("found: " + aText[i].text);
return aText[i];
I'm still learning, have I approached this wrong? Should I have used an object instead of an array?
And how come I don't get any results?
I've made an example app so you can see the code in an working environment.
Any kind of advice, feedback or criticism is more than welcome.
full example code
import React, Component from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
// Row comparison function
const rowHasChanged = (r1, r2) => r1.id !== r2.id;
// DataSource template object
const ds = new ListView.DataSource( rowHasChanged );
export default class App extends Component
state =
dataSource: ds.cloneWithRows(rows),
rows
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const aText = this.state.rows;
const filteredTexts = this.state.rows.filter(checkText);
console.log("text: " + JSON.stringify(filteredTexts));
function checkText()
var i;
for (i = 0; i < textLength; i++)
if (aText[i].text === searchText)
console.log("found: " + aText[i].text);
return aText[i];
this.setState(
searchText,
dataSource: this.state.dataSource.cloneWithRows(filteredTexts)
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.text
rowData.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<ListView
style=styles.container
dataSource=this.state.dataSource
renderRow=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
container:
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue"
);
AppRegistry.registerComponent("App", () => App);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
reactjs react-native
reactjs react-native
asked Nov 13 '18 at 9:11
SalmanSalman
2119
2119
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
I've suggest to use FlatList since ListView is depricated. I've rewrite your code a bit and you can check it on Expo Snack or just look into code below
import React, Component from "react";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput,
FlatList
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
export default class App extends Component
state =
rows,
filteredRows: rows,
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const filteredTexts = this.state.rows.filter(row =>
return row.text.indexOf(searchText) !== -1;
);
console.log("text: " + JSON.stringify(filteredTexts));
this.setState(
searchText,
filteredRows: filteredTexts
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.item.text
rowData.item.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<FlatList
style=styles.container
data=this.state.filteredRows
renderItem=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
SearchBarContainer:
marginTop: 40,
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue",
color: 'black',
,
);
Amazing, thank you Dimitri. I'm still learning and this helps alot as I try to reverse engineer your code and see what you do. I see it's a lot of JavaScript. I read the docs of react native and react native express. Any other helpful websites you might recommend?
– Salman
Nov 13 '18 at 10:07
@Salman not sure if it is ok share such information here, please contact me directly I'll share some great resources. You can find contact info in my profile.
– Dmitri Portenko
Nov 13 '18 at 10:10
add a comment |
You don't seem to have a state to hold the searchText
state =
dataSource: ds.cloneWithRows(rows),
rows,
searchText:"" //ADD THIS
;
add a comment |
This is very simple you don't need to use for loop to search from the array.
You can get your desired result by simply filter by text match in the object.
I have fixed your example app you can test it.
just replace your looped function with this line const filteredTexts = this.state.rows.filter(record => record.text.toLowerCase().match(searchText));
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277450%2fsearch-input-appears-empty-with-listview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've suggest to use FlatList since ListView is depricated. I've rewrite your code a bit and you can check it on Expo Snack or just look into code below
import React, Component from "react";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput,
FlatList
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
export default class App extends Component
state =
rows,
filteredRows: rows,
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const filteredTexts = this.state.rows.filter(row =>
return row.text.indexOf(searchText) !== -1;
);
console.log("text: " + JSON.stringify(filteredTexts));
this.setState(
searchText,
filteredRows: filteredTexts
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.item.text
rowData.item.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<FlatList
style=styles.container
data=this.state.filteredRows
renderItem=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
SearchBarContainer:
marginTop: 40,
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue",
color: 'black',
,
);
Amazing, thank you Dimitri. I'm still learning and this helps alot as I try to reverse engineer your code and see what you do. I see it's a lot of JavaScript. I read the docs of react native and react native express. Any other helpful websites you might recommend?
– Salman
Nov 13 '18 at 10:07
@Salman not sure if it is ok share such information here, please contact me directly I'll share some great resources. You can find contact info in my profile.
– Dmitri Portenko
Nov 13 '18 at 10:10
add a comment |
I've suggest to use FlatList since ListView is depricated. I've rewrite your code a bit and you can check it on Expo Snack or just look into code below
import React, Component from "react";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput,
FlatList
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
export default class App extends Component
state =
rows,
filteredRows: rows,
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const filteredTexts = this.state.rows.filter(row =>
return row.text.indexOf(searchText) !== -1;
);
console.log("text: " + JSON.stringify(filteredTexts));
this.setState(
searchText,
filteredRows: filteredTexts
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.item.text
rowData.item.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<FlatList
style=styles.container
data=this.state.filteredRows
renderItem=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
SearchBarContainer:
marginTop: 40,
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue",
color: 'black',
,
);
Amazing, thank you Dimitri. I'm still learning and this helps alot as I try to reverse engineer your code and see what you do. I see it's a lot of JavaScript. I read the docs of react native and react native express. Any other helpful websites you might recommend?
– Salman
Nov 13 '18 at 10:07
@Salman not sure if it is ok share such information here, please contact me directly I'll share some great resources. You can find contact info in my profile.
– Dmitri Portenko
Nov 13 '18 at 10:10
add a comment |
I've suggest to use FlatList since ListView is depricated. I've rewrite your code a bit and you can check it on Expo Snack or just look into code below
import React, Component from "react";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput,
FlatList
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
export default class App extends Component
state =
rows,
filteredRows: rows,
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const filteredTexts = this.state.rows.filter(row =>
return row.text.indexOf(searchText) !== -1;
);
console.log("text: " + JSON.stringify(filteredTexts));
this.setState(
searchText,
filteredRows: filteredTexts
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.item.text
rowData.item.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<FlatList
style=styles.container
data=this.state.filteredRows
renderItem=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
SearchBarContainer:
marginTop: 40,
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue",
color: 'black',
,
);
I've suggest to use FlatList since ListView is depricated. I've rewrite your code a bit and you can check it on Expo Snack or just look into code below
import React, Component from "react";
import
AppRegistry,
ListView,
View,
Text,
StyleSheet,
TextInput,
FlatList
from "react-native";
// Row data (hard-coded)
const rows = [
id: 0, text: "View" ,
id: 1, text: "Text" ,
id: 2, text: "Image" ,
id: 3, text: "ScrollView" ,
id: 4, text: "ListView" ,
id: 5, text: " ", text2: "test"
];
export default class App extends Component
state =
rows,
filteredRows: rows,
;
setSearchText(event)
const searchText = event.nativeEvent.text;
const textLength = this.state.rows.length;
const filteredTexts = this.state.rows.filter(row =>
return row.text.indexOf(searchText) !== -1;
);
console.log("text: " + JSON.stringify(filteredTexts));
this.setState(
searchText,
filteredRows: filteredTexts
);
renderRow = rowData =>
return (
<Text style=styles.row>
rowData.item.text
rowData.item.text2
</Text>
);
;
render()
return (
<View style=styles.SearchBarContainer>
<TextInput
placeholder="Search"
value=this.state.searchText
onChange=this.setSearchText.bind(this)
style=styles.searchBar
underlineColorAndroid="#DD016B"
selectionColor="#DD016B"
/>
<FlatList
style=styles.container
data=this.state.filteredRows
renderItem=this.renderRow
/>
</View>
);
const styles = StyleSheet.create(
SearchBarContainer:
marginTop: 40,
flex: 1
,
row:
padding: 15,
marginBottom: 5,
backgroundColor: "skyblue",
color: 'black',
,
);
answered Nov 13 '18 at 9:43
Dmitri PortenkoDmitri Portenko
618520
618520
Amazing, thank you Dimitri. I'm still learning and this helps alot as I try to reverse engineer your code and see what you do. I see it's a lot of JavaScript. I read the docs of react native and react native express. Any other helpful websites you might recommend?
– Salman
Nov 13 '18 at 10:07
@Salman not sure if it is ok share such information here, please contact me directly I'll share some great resources. You can find contact info in my profile.
– Dmitri Portenko
Nov 13 '18 at 10:10
add a comment |
Amazing, thank you Dimitri. I'm still learning and this helps alot as I try to reverse engineer your code and see what you do. I see it's a lot of JavaScript. I read the docs of react native and react native express. Any other helpful websites you might recommend?
– Salman
Nov 13 '18 at 10:07
@Salman not sure if it is ok share such information here, please contact me directly I'll share some great resources. You can find contact info in my profile.
– Dmitri Portenko
Nov 13 '18 at 10:10
Amazing, thank you Dimitri. I'm still learning and this helps alot as I try to reverse engineer your code and see what you do. I see it's a lot of JavaScript. I read the docs of react native and react native express. Any other helpful websites you might recommend?
– Salman
Nov 13 '18 at 10:07
Amazing, thank you Dimitri. I'm still learning and this helps alot as I try to reverse engineer your code and see what you do. I see it's a lot of JavaScript. I read the docs of react native and react native express. Any other helpful websites you might recommend?
– Salman
Nov 13 '18 at 10:07
@Salman not sure if it is ok share such information here, please contact me directly I'll share some great resources. You can find contact info in my profile.
– Dmitri Portenko
Nov 13 '18 at 10:10
@Salman not sure if it is ok share such information here, please contact me directly I'll share some great resources. You can find contact info in my profile.
– Dmitri Portenko
Nov 13 '18 at 10:10
add a comment |
You don't seem to have a state to hold the searchText
state =
dataSource: ds.cloneWithRows(rows),
rows,
searchText:"" //ADD THIS
;
add a comment |
You don't seem to have a state to hold the searchText
state =
dataSource: ds.cloneWithRows(rows),
rows,
searchText:"" //ADD THIS
;
add a comment |
You don't seem to have a state to hold the searchText
state =
dataSource: ds.cloneWithRows(rows),
rows,
searchText:"" //ADD THIS
;
You don't seem to have a state to hold the searchText
state =
dataSource: ds.cloneWithRows(rows),
rows,
searchText:"" //ADD THIS
;
answered Nov 13 '18 at 9:16
Naveed SheriffdeenNaveed Sheriffdeen
424215
424215
add a comment |
add a comment |
This is very simple you don't need to use for loop to search from the array.
You can get your desired result by simply filter by text match in the object.
I have fixed your example app you can test it.
just replace your looped function with this line const filteredTexts = this.state.rows.filter(record => record.text.toLowerCase().match(searchText));
add a comment |
This is very simple you don't need to use for loop to search from the array.
You can get your desired result by simply filter by text match in the object.
I have fixed your example app you can test it.
just replace your looped function with this line const filteredTexts = this.state.rows.filter(record => record.text.toLowerCase().match(searchText));
add a comment |
This is very simple you don't need to use for loop to search from the array.
You can get your desired result by simply filter by text match in the object.
I have fixed your example app you can test it.
just replace your looped function with this line const filteredTexts = this.state.rows.filter(record => record.text.toLowerCase().match(searchText));
This is very simple you don't need to use for loop to search from the array.
You can get your desired result by simply filter by text match in the object.
I have fixed your example app you can test it.
just replace your looped function with this line const filteredTexts = this.state.rows.filter(record => record.text.toLowerCase().match(searchText));
answered Nov 13 '18 at 9:40
Junaid azizJunaid aziz
7114
7114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277450%2fsearch-input-appears-empty-with-listview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown