Search input appears empty with ListView










1















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);









share|improve this question


























    1















    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);









    share|improve this question
























      1












      1








      1








      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);









      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 9:11









      SalmanSalman

      2119




      2119






















          3 Answers
          3






          active

          oldest

          votes


















          1














          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',
          ,
          );





          share|improve this answer























          • 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


















          1














          You don't seem to have a state to hold the searchText



          state = 
          dataSource: ds.cloneWithRows(rows),
          rows,
          searchText:"" //ADD THIS
          ;





          share|improve this answer






























            1














            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));






            share|improve this answer






















              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
              );



              );













              draft saved

              draft discarded


















              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









              1














              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',
              ,
              );





              share|improve this answer























              • 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















              1














              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',
              ,
              );





              share|improve this answer























              • 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













              1












              1








              1







              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',
              ,
              );





              share|improve this answer













              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',
              ,
              );






              share|improve this answer












              share|improve this answer



              share|improve this answer










              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

















              • 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













              1














              You don't seem to have a state to hold the searchText



              state = 
              dataSource: ds.cloneWithRows(rows),
              rows,
              searchText:"" //ADD THIS
              ;





              share|improve this answer



























                1














                You don't seem to have a state to hold the searchText



                state = 
                dataSource: ds.cloneWithRows(rows),
                rows,
                searchText:"" //ADD THIS
                ;





                share|improve this answer

























                  1












                  1








                  1







                  You don't seem to have a state to hold the searchText



                  state = 
                  dataSource: ds.cloneWithRows(rows),
                  rows,
                  searchText:"" //ADD THIS
                  ;





                  share|improve this answer













                  You don't seem to have a state to hold the searchText



                  state = 
                  dataSource: ds.cloneWithRows(rows),
                  rows,
                  searchText:"" //ADD THIS
                  ;






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 9:16









                  Naveed SheriffdeenNaveed Sheriffdeen

                  424215




                  424215





















                      1














                      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));






                      share|improve this answer



























                        1














                        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));






                        share|improve this answer

























                          1












                          1








                          1







                          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));






                          share|improve this answer













                          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));







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 13 '18 at 9:40









                          Junaid azizJunaid aziz

                          7114




                          7114



























                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              這個網誌中的熱門文章

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                              Museum of Modern and Contemporary Art of Trento and Rovereto