0

Anybody Please format my question so that I can post ? Q) search text in each row of the model and highlight it is found. code is below.

<tbody>
foreach(var item in @Model.Rows)
{
    <tr>
    @if(Model.SearxhText!=null &&     Model.SearchText.Length>0)
    {
        for(int i=0;i<=item.Length-1;i++)
        {
            if(item[i].IndexOf(Model.SearchText,0,StringComparison.CurrentCultureIgnoreCase)!=-1)
            {
                <td>
                <span style="color:blue">@Model.SearchText</span>remainingtex    t</td>
            }
        else
        {
            <td> @item[i]</td>
        }
}
</tr>
}
</tbody>
faiz
  • 1
  • 2
  • you see some to have several typos in your post. You are missing a }, the ` – Tyler Mar 31 '17 at 16:28
  • s m on mobile so few typing mistakes. – faiz Mar 31 '17 at 16:39
  • it's stringcomparison.cultureinfo and no "." after span – faiz Mar 31 '17 at 16:40
  • 1
    you should be able to edit your own questions. – Tyler Mar 31 '17 at 16:42
  • are we selecting all the text in the td or a range of text? What type of text are we looking? – Tyler Apr 01 '17 at 12:54
  • are you against using plugins? It seems it is highly recommended to use plugins due many complicated issues related to the DOM structure in HTML. The answer linked below will also suggest Mark.js and JQuery plugins as a solution (I personally have no experience in these two plugins). See this answer for more info: http://stackoverflow.com/a/34614703/6009304 – Tyler Apr 01 '17 at 13:04
  • My TeamLead is against using dataTable. Besides, it should be done in tag of a simple html table. Model is passing 30 records with 4 columns and we have to search each column in each record for any entered character in the global search box. Moreover, we are taken to the browser as soon as the last record is looped.The alert message written in documemt.ready () is also executing after the table is displayed. so, we have to highlight "m" in ' Mr', 'Gimmy', etc., in itself. – faiz Apr 01 '17 at 17:05
  • There is a global search box in which when the user enters any character like 'm' then from database all the records (30 suppose) will be looped in foreach in a html table in .cshtml file ( see code in the question). Then wherever we find 'm' in each column of each record , it is highlighted with orange color and bold font. This should be done in itself. How about calling JavaScript function within and bold +color the searched text? will it be possible. Please answer. – faiz Apr 01 '17 at 17:13
  • I could be wrong; however, it looks like DataTables and tablesorter is not required for Mark.js. If I am right about this, then Mark.js looks like a perfect match for what you and your team wants. Also, you can customize the highlighting with Mark.js by editting the css, which is shown on their page at section 3.4 Styling. This would allow any effects, such as bolding or specific colors. – Tyler Apr 01 '17 at 18:43

0 Answers0