חייב עזרה ב-java script עם קוד מסוים - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

חייב עזרה ב-java script עם קוד מסוים


11iceman11

Recommended Posts

שלום לכולם,

אני רוצה להשתמש בקוד שקיים באתר הנ"ל:

http://www.codeproject.com/jscript/TableFilter.asp

עם שינוי מסוים שאני לא יודע איך עושים אותו ואשמח אם מישהו יוכל לעזור לי או לשלוח לי קוד המאפשר זאת כי אני לא בדיוק מתמצא ב-JS.

כפי שניתן לראות באתר ניתן להזין את השדה הרצוי לחיפווש או לסנן מתוך רשימה.

במקום האפשרויות הנ"ל, אני רוצה שיהיו לינקים שמהם יבוצע החיפוש, לדוגמא :

יהיה לינק שבו רשום המילה "Joe" ובעת לחיצה על המילה תבצע את החיפוש ותציג לי רק את האפשרויות שעונות על החיפוש בטבלה...

איך עושים את זה, מישהו יכול לעזור לי ?

תודה מראש.

קישור לתוכן
שתף באתרים אחרים

1) זה לא עובד בFF.

2)



<input type="button" value="Joe" TF_colKey="name" TF_searchType="full"
onkeyup="TF_filterTable(dataTable, filter)">

תנסה, אולי יעבוד(לא ניסיתי בעצמי).

עריכה: ד.א. שים לב שהוא מבחין בין אותיות גדולות לקטנות. אולי כדאי לך לשנות את זה.

קישור לתוכן
שתף באתרים אחרים

שים לב למה שבאדום אתה פשוט צריך להוסיף בפונקציות של הג'וואה סקריפט את התייחסות למקרה של כפתור הכיל את הפרמטרים והערך

לדעתי זה יפתור לך הבעיה


function _TF_shouldShow(type, con, cell) {
var toshow=true;
if (type != null) type = type.toLowerCase();
switch (type)
{
case "checkbox": //condition is for checkbox
//so lets find out if the cell contains a checkbox
var aInputs = cell.all.tags("INPUT"); //check for input tags
for (var i=0;i<aInputs.length;i++)
{ //and look for the first checked item
if (aInputs[i].type == "checkbox")
{
toshow = (con.toLowerCase() == (aInputs[i].checked?"true":"false"));
if (toshow) break;
}
}
break
case "item":
var strarray = cell.innerText.split(",");
innershow = false;
for (var ss=0;ss<strarray.length;ss++){
if (con==_TF_trimWhitespace(strarray[ss])){
innershow=true;
break;
}
}
if (innershow == false)
toshow=false;
break
case "full":
if (cell.innerText!=con)
toshow = false;
break
case "substring":
if (cell.innerText.indexOf(con)<0)
toshow = false;
break
[color=red]case "button":
//write the code to handle the data from the input button
break[/color]
default: //is "substring1" search
if (cell.innerText.indexOf(con)!=0) //pattern must start from 1st char
toshow = false;
if (con.charAt(con.length-1) == " ")
{ //last char is a space, so lets do a full search as well
if (_TF_trimWhitespace(con) != cell.innerText)
toshow = false;
else
toshow = true;
}
break
}
return toshow;
}


function TF_filterTable(tb, frm) {
var conditions = new Array();
if (frm.style.display == "none") //filtering is off
return _TF_showAll(tb);

//go thru each type of input elements to figure out the filter conditions
var inputs = frm.tags("INPUT");
for (var i=0;i<inputs.length;i++)
{ //looping thru all INPUT elements
if (inputs[i].getAttribute("TF_colKey") == null) //attribute not found
continue; //we assume that this input field is not for us
switch (inputs[i].type)
{
[color=red]case "button":
//write the code to handle the data from the input button
break[/color]
case "text":
case "hidden":
if(inputs[i].value != "")
{
index = conditions.length;
conditions[index] = new Object;
conditions[index].name = inputs[i].getAttribute("TF_colKey");
conditions[index].type = inputs[i].getAttribute("TF_searchType");
conditions[index].value = inputs[i].value;
conditions[index].single = true;
}
break
case "checkbox":
if(inputs[i].isDisabled == false)
{
index = conditions.length;
conditions[index] = new Object;
conditions[index].name = inputs[i].getAttribute("TF_colKey");
conditions[index].type = "checkbox";
conditions[index].value = inputs[i].checked?"true":"false";
conditions[index].single = true;
}
break
}
}
var inputs = frm.tags("SELECT");
//able to do multiple selection box
for (var i=0;i<inputs.length;i++)
{ //looping thru all SELECT elements
if (inputs[i].getAttribute("TF_colKey") == null) //attribute not found
continue; //we assume that this input field is not for us
var opts = inputs[i].options;
var optsSelected = new Array();
for (intLoop=0; intLoop<opts.length; intLoop++)
{ //looping thru all OPTIONS elements
if (opts[intLoop].selected && (opts[intLoop].getAttribute("TF_not_used") == null))
{
index = optsSelected.length;
optsSelected[index] = opts[intLoop].value;
}
}
if (optsSelected.length > 0) //has selected items
{
index = conditions.length;
conditions[index] = new Object;
conditions[index].name = inputs[i].getAttribute("TF_colKey");
conditions[index].type = inputs[i].getAttribute("TF_searchType");
conditions[index].value = optsSelected;
conditions[index].single = false;
}
}
//ok, now that we have all the conditions, lets do the filtering proper
_TF_filterTable(tb, conditions);
}


function _TF_get_value(input) {
switch (input.type)
{
[color=red]case "button":
//write the code to handle the data from the input button
break[/color]

case "text":
return input.value;
break
case "select-one":
if (input.selectedIndex > -1) //has value
return input.options(input.selectedIndex).value;
else
return "";
break;
}
}

קישור לתוכן
שתף באתרים אחרים

גם לא טוב אבל יש שיפור.

כעת מתבצע חיפוש לפי ערך אחד בלבד.

כלומר אם יצרתי 2 כפתורים שלכל אחד יש ערך שונה (joe,dan), הוא מחזיר לי כל פעם רק את הערך joe.

הסבר:

אם אני לוחץ על joe הוא מחזיר לי את joe, אך שים לב אם אני לוחץ על dan הוא מחזיר לי גם את joe....

אני מתחיל להתייאש...

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...