WebSite X5Help Center

 
Hanafi Salman
Hanafi Salman
User

Script for search specific data in a table  en

Автор: Hanafi Salman
Просмотрено 284, Подписчики 1, Размещенный 0  

Need help again for search specific data I am using TableObject and display in one row for the result.. search from the name inside the search box.

The link is:

https://ica.web.id/daftartel.html

Thanks so much

Размещено
38 Ответы - 1 Полезно
Axel  
Axel  
User

into your browser :  CTRL + F 

no ?

Читать больше
Размещено От Axel  
Hanafi Salman
Hanafi Salman
User
Автор

I am sorry.. it is not what I mean

I mean that only one row display and its on top

Читать больше
Размещено От Hanafi Salman
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator

...try this code of mine, derived from the previous one, blindly (!)cool; if it doesn't work for you, forget itfoot-in-mouth, bye...

<script>
$(document).ready(function () {
/** -- cerca in tabella x WSx5 by KolAsim -- **/
const targetContainer = $("#imTableObject_39_01");
//-------------------K---------------------------
const table = targetContainer.find("table"); const tbody = table.find("tbody"); const searchBox = $(` <div id="dynamicSearchBar" style="margin-bottom:10px; text-align:left;"> <input type="text" id="searchInput_dyn" placeholder="Cerca..."> <button id="prevBtn_dyn"> ◄ </button> <button id="nextBtn_dyn"> ► </button> <button id="resetBtn_dyn">Reset</button> <span id="resultCount" style="margin-left:10px;"></span> </div> `); targetContainer.prepend(searchBox); $("head").append(` <style> .highlightMatch { background: yellow; padding: 0 2px; } .highlightCurrent { background: orange !important; padding: 0 2px; } </style> `); function removeHighlight() { tbody.find(".highlightMatch, .highlightCurrent").each(function () { $(this).replaceWith($(this).text()); }); } function highlight(text) { if (!text) return; const escaped = text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); const pattern = new RegExp("(" + escaped + ")", "gi"); tbody.find("td").each(function () { const original = $(this).text(); if (pattern.test(original)) { const newHtml = original.replace(pattern, `<span class="highlightMatch">$1</span>`); $(this).html(newHtml); } }); } let currentIndex = -1; function updateCounter() { const matches = tbody.find(".highlightMatch, .highlightCurrent"); if (matches.length === 0) { $("#resultCount").text("Risultati: 0 / 0"); } else { $("#resultCount").text(`Risultati: ${currentIndex + 1} / ${matches.length}`); } } function gotoMatch(next = true) { const matches = tbody.find(".highlightMatch, .highlightCurrent"); if (matches.length === 0) return; matches.removeClass("highlightCurrent").addClass("highlightMatch"); if (next) { currentIndex++; if (currentIndex >= matches.length) currentIndex = 0; } else { currentIndex--; if (currentIndex < 0) currentIndex = matches.length - 1; } const $current = $(matches[currentIndex]); $current.removeClass("highlightMatch").addClass("highlightCurrent"); $('html, body').animate({ scrollTop: $current.offset().top - 100 }, 300); updateCounter(); } $("#searchInput_dyn").on("input", function () { const filter = $(this).val().toLowerCase(); removeHighlight(); currentIndex = -1; if (filter === "") { updateCounter(); return; } highlight(filter); gotoMatch(true); }); $("#nextBtn_dyn").on("click", function () { gotoMatch(true); }); $("#prevBtn_dyn").on("click", function () { gotoMatch(false); }); $("#resetBtn_dyn").on("click", function () { $("#searchInput_dyn").val(""); removeHighlight(); currentIndex = -1; updateCounter(); }); });/**K**/
</script>

.

Читать больше
Размещено От  ‪ KolAsim ‪ ‪
Hanafi Salman
Hanafi Salman
User
Автор

Thanks @KolAsim, the script works as usual and can find each data I am looking for by highlighted word.

Actually what I want that the results display each row whose data is found, while other data that is not searched does not appear.

Anyway, Thank you so much for always providing solutions.

Читать больше
Размещено От Hanafi Salman
Hanafi Salman
Hanafi Salman
User
Автор

Thanks to give the solution before for search and filter data on TextObject X5.. 

https://ica.web.id/daftarsma.html

I am still waiting for TableObject X5 applied..

Thanks @KolAsim 

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

The code from w3schools.com works with the "Table" object in WebSite X5, but only 1 column is searched. If several columns are to be searched, a Javascript expert, e.g. KolAsim, would have to adapt the code or offer Javascript code themselves.

My test page >> https://findelinks.de/123test-aufklappmenue-2/suche-in-tabelle.html

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

@Daniel, the test page you created is great, only the column header titles are still not displayed..

Would you mind providing the script here?

While waiting for @KolAsim.. would have to adapt the code or offer Javascript code themselves, to make it perfect.

Thanks @Daniel..

Читать больше
Размещено От Hanafi Salman
Hanafi Salman
Hanafi Salman
User
Автор

I try to make one sample table follow the script using HTML code Object, but I do not understand where I put a TableObject website X5 code inside the script..

https://ica.web.id/filtertab.html

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

2 Screenshots below.

Objects in the grid and their contents:

1)a) Insert in the first HTML code objekt at "HTML code" this code only:

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Suche nach Früchten ...">

   b) Insert in the first HTML code objekt at "Extended" the complete CSS code from ...

>>> https://www.w3schools.com/howto/howto_js_filter_table.asp

       ("Extended" could be called differently in the English version)

2) Here are die table objekt from WebSite X5

3) Insert in the second HTML code objekt the Javascript code complete (> w3schools.com)

Changed this line in Javascript (The numbers vary from user to user, so be sure to adjust!)

table = document.getElementById("imTableObject_71_03");

-----

-----

Читать больше
Размещено От Daniel W.
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

Adjust the 7th line in the code, the rest stays as it is.

Mark the table object in the grid and click on "Code" at the top, then you will see the object ID on the right, insert it as shown in the code below.

----- Javascript code -----

<script>
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("imTableObject_71_03");
tr = table.getElementsByTagName("tr");

// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

Yes Daniel, I follow your instruction, it works.. 

https://ica.web.id/daftartel.html

The one thing is that it still can't display the header row, hope @KolAsim will help or by using his own script.

Anyway, thanks so much @Daniel

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

Change in this code the placholder text in your langage and your search.

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Suche nach Früchten ...">

Which header row do you mean?

Читать больше
Размещено От Daniel W.
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

Upon request, KolAsim may be able to provide additional functions that I, as a non-expert, cannot do.

Читать больше
Размещено От Daniel W.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator

 ... OK ... Hi everyone, this code is also a "take it or leave it" code, extracted from my previous codes already posted in the search topics. Hi, ciao...

<script>
/** -- cerca in tabella evidenzia con esclusione negativi x WSx5 by KolAsim -- **/
$(document).ready(function () {
const targetContainer = $("#imTableObject_39_01");
//----------K--------------------------------
const table = targetContainer.find("table"); const tbody = table.find("tbody"); const searchBox = $(` <div id="dynamicSearchBar" style="margin-bottom:10px;"> <input type="text" id="searchInput_dyn" placeholder="Cerca..."> <button id="searchBtn_dyn" class="searchBtnModern">&#128269; Cerca</button> <button id="resetBtn_dyn" class="resetBtnModern">⟲ Reset</button> </div> `); targetContainer.prepend(searchBox); $("head").append(` <style> #dynamicSearchBar { display: flex; gap: 6px; align-items: center; } #searchInput_dyn { padding: 7px 12px; border: 1px solid #aaa; border-radius: 4px; font-size: 15px; width: 250px; } .searchBtnModern { padding: 7px 12px; border: none; background: #007bff; color: white; border-radius: 4px; cursor: pointer; } .resetBtnModern { padding: 7px 12px; border: none; background: #dc3545; color: white; border-radius: 4px; cursor: pointer; } .highlightSearch { background-color: yellow; font-weight: bold; } </style> `); function performSearch() { const filter = $("#searchInput_dyn").val().toLowerCase(); tbody.find("tr").each(function () { const row = $(this); const rowText = row.text().toLowerCase(); row.toggle(rowText.includes(filter)); row.find("td").each(function () { const original = $(this).text(); $(this).html(original); }); if (filter.trim() !== "" && rowText.includes(filter)) { row.find("td").each(function () { const cell = $(this); const text = cell.text(); const lower = text.toLowerCase(); const idx = lower.indexOf(filter); if (idx !== -1) { const before = text.substring(0, idx); const match = text.substring(idx, idx + filter.length); const after = text.substring(idx + filter.length); cell.html(`${before}<span class="highlightSearch">${match}</span>${after}`); } }); } }); } $("#searchBtn_dyn").on("click", function () { performSearch(); }); $("#searchInput_dyn").on("keypress", function (e) { if (e.which === 13) { $("#searchBtn_dyn").click(); e.preventDefault(); } }); $("#resetBtn_dyn").on("click", function () { $("#searchInput_dyn").val(""); tbody.find("tr").show(); tbody.find("td").each(function () { const original = $(this).text(); $(this).html(original); }); }); });/*K*/
</script>  

.

Читать больше
Размещено От  ‪ KolAsim ‪ ‪
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

@KolAsim:

I didn't use your code because I had big problems with it twice, but the code from w3schools.com.

On my test site I had adjusted the code, but I could only search 1 table column with it.

Now I have expanded a line of code so that all 3 table columns are searched, but the JavaScript does not find all text fragments in the search in the table.

Is this a quirk in javascript or a bug in my changed code?

My test page after change, see

>> https://findelinks.de/123test-aufklappmenue-2/suche-in-tabelle.html

.

---- Javascript code line before -----

td = tr[i].getElementsByTagName("td")[0];

---- Javascript Code line after -----

td = tr[i].getElementsByTagName("td")[0] && tr[i].getElementsByTagName("td")[1] && tr[i].getElementsByTagName("td")[2];

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

@Daniel,

I mean row contained title in each column.  I accidentally changed this value to 1 and the row header appears.

https://ica.web.id/daftartel2.html

Thank you so much for your help..

Читать больше
Размещено От Hanafi Salman
Hanafi Salman
Hanafi Salman
User
Автор

@KolAsim,

The script works well and complete with search and reset buttons

https://ica.web.id/daftartel.html

Thanks lots.. I never forget all your help

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

Thanks, now I understand it and changed it on my test site too.

I have almost no knowledge of Javascript, only some basic knowledge of PHP, as I worked with PHP as a hobby for about a year in 2007.

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

I am sorry @KolAsim, one more.. how to make the row header appear for the search result.. what code should be changed or replaced in the script..

Читать больше
Размещено От Hanafi Salman
Hanafi Salman
Hanafi Salman
User
Автор

@Daniel.. Great PHP specialist, since 2007.. so long.

One more Daniel need your help,

I can not applied for filter using TextObject websiteX5 contained list, it doesn't work.. but for TableObject websiteX5 well done as your instruction.. 

https://ica.web.id/listfilter.html

Maybe I am wrong to put ID code for TextObject X5

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

I only worked with PHP for about 15 months in 2006/2007, but then had to stop because it became too much for my head.

Back to the code.

  • The code from w3schools and KolAsim was written specifically for the HTML tables that are also used by the WebSite X5 table object.
  • The code from w3schools and KolAsim is not suitable for the Text object of WebSite X5, even if you design the text to look like a table.

KolAsim has other scripts to search in the text object, but I don't have a list of KolAsim's posts and codes.

Addendum: I removed the table and the Javascript code from my test site because the code from w3schools did not work without errors.

Читать больше
Размещено От Daniel W.
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

Is the code in the screenshot also from w3schools?

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

But I follow the code from w3schools.. not Filter Table but Filter List.. I guess for the list the same as document like Text Object of WebsiteX5

https://www.w3schools.com/howto/howto_js_filter_lists.asp

Anyway.. thanks for your explanation @Daniel

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

For this w3schools code you need 1 HTML object for all codes otherwise it won't work.

The text must then be written as HTML list code, i.e. without the functions of the text object.

This means that everything that is not in the list can be designed with text objects at the top and bottom.

.

----- HTML code objekt -----

Tab "Advanced":

Insert the CSS code

Tab "Advanced":

Insert the HTML code

Insert the Javascript code

-------------------------------

That would be option 1, but I'm also trying to make it easier.

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

You mean Tab "Expert" ?

Then insert HTM+JS code

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

I have the German version of WebSie X5, I think the English version is called "Expert".

Читать больше
Размещено От Daniel W.
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

If you want the list to be left-aligned, then in this section add a line with text-align: left; add.

-----

#myUL {
/* Remove default list styling */
list-style-type: none;
text-align: left;
padding: 0;
margin: 0;
}

-----

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

It doesn't work, perhaps I do mistake?

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

Don´t change the Javascript Code.

Читать больше
Размещено От Daniel W.
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

-----

Читать больше
Размещено От Daniel W.
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

"Expert" only for CSS.

"HTML Code" first HTML, then Javascript.

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

My test page > https://ica.web.id/listfilter2.html

The search box does not appear

CSS Code on Tab Expert

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Suche nach Früchten ...">
<script>
function myFunction() {
// Declare variables
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById('myInput');
filter = input.value.toUpperCase();
ul = document.getElementById("imTextObject_44_03");
li = ul.getElementsByTagName('li');

// Loop through all list items, and hide those who don't match the search query
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
</script>

Читать больше
Размещено От Hanafi Salman
Hanafi Salman
Hanafi Salman
User
Автор

Owh.. it means that we can not put the TextObject of WebsiteX5 but TableObject of WebsiteX5 can be applied for the script Filter table before

Читать больше
Размещено От Hanafi Salman
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

I had planned the text object as option 2, but it didn't work, but I can test it again later when I know where the error was.

---- Wrong -----

ul = document.getElementById("imTextObject_44_03");

---- Correct -----

ul = document.getElementById("myUL");

Читать больше
Размещено От Daniel W.
Daniel W.
Daniel W.
User
Лучший пользователь месяца DEЛучший пользователь месяца EN

This is the CSS code für "Experts" in the HTML Code objekt:

#myInput {
  background-image: url('/css/searchicon.png');/* Add a search icon to input */
  background-position: 10px 12px;/* Position the search icon */
  background-repeat: no-repeat;/* Do not repeat the icon image */
  width: 100%;/* Full-width */
  font-size: 16px;/* Increase font-size */
  padding: 12px 20px 12px 40px;/* Add some padding */
  border: 1px solid #ddd;/* Add a grey border */
  margin-bottom: 12px;/* Add some space below the input */
}

#myUL {
  /* Remove default list styling */
  list-style-type: none;
  padding: 0;
  margin: 0;
}

#myUL li a {
  border: 1px solid #ddd;/* Add a border to all links */
  margin-top: -1px;/* Prevent double borders */
  background-color: #f6f6f6;/* Grey background color */
  padding: 12px;/* Add some padding */
  text-decoration: none;/* Remove default text underline */
  font-size: 18px;/* Increase the font-size */
  color: black;/* Add a black text color */
  display: block;/* Make it into a block element to fill the whole list */
}

#myUL li a:hover:not(.header) {
  background-color: #eee;/* Add a hover effect to all links, except for headers */
}

Читать больше
Размещено От Daniel W.
Hanafi Salman
Hanafi Salman
User
Автор

Ok I understand.. Thanks @Daniel

Читать больше
Размещено От Hanafi Salman