अरे दोस्तों, मैं जे एस में एक अच्छा त्रिकोणीय राज्य चेकबॉक्स नियंत्रक के लिए देख रहा हूँ? मुझे सिफारिश करने के लिए कुछ भी मिल गया?
राज्यों मैं तलाश कर रहा हूँ कर रहे हैं
- चेक किए गए
- अनियंत्रित
- उदासीन (कभी नहीं की जाँच की थी / अनियंत्रित)
अरे दोस्तों, मैं जे एस में एक अच्छा त्रिकोणीय राज्य चेकबॉक्स नियंत्रक के लिए देख रहा हूँ? मुझे सिफारिश करने के लिए कुछ भी मिल गया?
राज्यों मैं तलाश कर रहा हूँ कर रहे हैं
रेडियो बटन का प्रयोग करें।
<input type="radio" name="tristate" value="checked" />Checked
<input type="radio" name="tristate" value="unchecked" />Unchecked
यदि कोई भी अगर रेडियो चालू हैं, तो आप अपने तीसरे "उदासीन" या अशक्त राज्य की है।
आप ExtJS पर गौर कर सकते हैं।
वे एक बड़ा समुदाय है, जो अक्सर इस तरह बातें बनाता है और मुझे यकीन है कि अगर आप एक यह ऊपर आ सकता है के लिए googled हूँ। असल में ये रहा कि आप इस के लिए कुछ परिवर्तन करते हैं और काम करने के लिए आप कैसे चाहते हैं कि उसे प्राप्त करने में सक्षम हो सकता है:
http://extjs.net/forum/showthread.php?t=28096
उम्मीद है की यह मदद करेगा!
आप एक से अधिक दो राज्यों की जरूरत है, तो 3 रेडियो बटन का उपयोग करें।
उपयोगकर्ता तीसरा राज्य मतलब करने के लिए कुछ भी का चयन नहीं किया है, तो यह मानकर न चलें। क्या उपयोगकर्ता सवाल याद करता है, तो सब एक साथ, या गलती से प्रस्तुत हिट?
आप 3 राज्यों चाहते हैं, तो 3 राज्यों है!
का प्रयोग करें एचटीएमएल 5 अनिश्चित इनपुट तत्वों ।
मैं जबकि एक परियोजना पर काम इस समाधान का विकास किया। यह चेक बॉक्स की अनिश्चित राज्य (एक विशेषता है जो पहुँचा नहीं जा सकता / मार्कअप से सेट) का उपयोग करता है। मेरे उदाहरण में, मैं घोंसले में से केवल एक स्तर है, लेकिन यह, संयुक्त राष्ट्र होने के लिए समूहों और उप समूहों के लिए अनुमति देने के लिए सभी को अनिश्चित काल के नेस्ट किया जा सकता है, या आंशिक रूप से चयन किया।
बुनियादी संरचना इस तरह अनिश्चित विशेषता जोड़ तोड़ के आसपास घूमती है:
<input type="checkbox" value="HasFavoriteColor" name="FavoriteColor" id="myCheckBox" />
<input type="hidden" id="FavoriteColorState" name="FavoriteColorState" /><!-- potential values: 0, 1, -1 -->
<script type="text/javascript">
//using JQuery
$("#myCheckBox").prop("indeterminate", true);
//using pure javascript
document.getElementById("myCheckBox").setAttribute("indeterminate", true);
</script>
मैं एक का चयन करें-सब यहाँ मेरी उदाहरण में लिए इसका इस्तेमाल किया है, लेकिन यह सिर्फ एक व्यक्ति चेकबॉक्स पर इस्तेमाल किया जा सकता है। यह पता चला है कि इस सर्वर के लिए एक के बाद पीठ में राज्य संवाद नहीं करता है महत्वपूर्ण है। एक चेकबॉक्स पोस्ट किए जाने से केवल यूआई को प्रभावित करता है अभी भी सही / गलत तो अनिश्चित है। आप मान वापस पोस्ट करने के लिए की जरूरत है, तो आप कुछ छिपा क्षेत्र के लिए अनिश्चित राज्य टाई मूल्य लागू करने के लिए होगा।
अनिश्चित राज्य के बारे में अधिक के लिए, निम्न संसाधन देखें:
यहाँ एक काम कर उदाहरण (बाहरी बेला) है: http://jsfiddle.net/xDaevax/65wZt/
कार्य उदाहरण (ढेर स्निपेट):
var root = this;
root.selectedCount = 0;
root.totalCount = 0;
root.percentageSelected = 0.0;
root.holdTimer = 0;
jQuery.fn.customSelect = {
State: 0,
NextState: function () {
this.State += 1;
if (this.State > 2) {
this.State = 0;
} // end if
} // end object
};
function checkAllToggle(parent, toggle) {
if (parent != null && parent != undefined) {
parent.find("input[type='checkbox']").prop("checked", toggle);
for (var i = 0; i < parent.find("input[type='checkbox']").length; i++) {
$(document).trigger("item-selected", {
IsSelected: $(parent.find("input[type='checkbox']")[i]).prop("checked")
});
} // end for loop
} // end if
} // end function checkAll
var fadeTimer = setInterval(function () {
if (root.holdTimer > 0) {
root.holdTimer -= 1;
} else {
root.holdTimer = -2;
} // end if/else
if (root.holdTimer == -2) {
$(".options-status").fadeOut("easeOutBack");
root.holdTimer = -1;
} // end if/else
}, 50);
$(function () {
root.totalCount = $(document).find(".options-list input[type='checkbox']").length;
$(document).bind("select-state-change", function (e, data) {
switch (data.State) {
case 0:
data.Target.prop("checked", false);
data.Target.prop("indeterminate", false);
checkAllToggle($(".options-list"), false);
break;
case 1:
data.Target.prop("indeterminate", true);
e.preventDefault();
break;
case 2:
data.Target.prop("checked", true);
data.Target.prop("indeterminate", false);
checkAllToggle($(".options-list"), true);
break;
}
});
$(document).bind("item-selected", function (e, data) {
root.holdTimer = 50;
if (data != null && data != undefined) {
if (data.IsSelected) {
root.selectedCount += 1;
} else {
root.selectedCount -= 1;
} // end if/else
if (root.selectedCount > root.totalCount) {
root.selectedCount = root.totalCount;
} // end if
if (root.selectedCount < 0) {
root.selectedCount = 0;
} // end if
root.percentageSelected = (100 * (root.selectedCount / root.totalCount));
root.percentageSelected < 50 && root.percentageSelected >= 0 ? $(".options-status").removeClass("finally-there").removeClass("almost-there").addClass("not-there", 200) : false;
root.percentageSelected < 100 && root.percentageSelected >= 50 ? $(".options-status").removeClass("not-there").removeClass("finally-there").addClass("almost-there", 200) : false;
root.percentageSelected == 100 ? $(".options-status").removeClass("not-there").removeClass("almost-there").addClass("finally-there", 200) : false;
$(".options-status .output").text(root.percentageSelected + "%");
setTimeout(function () {
$(".options-status").fadeIn("easeInBack");
}, 100);
} // end if
});
$("#select-all").click(function (e) {
var checkbox = $(this);
if (checkbox.prop("checked") == true) {
checkbox.customSelect.State = 2;
} else {
checkbox.customSelect.State = 0;
} // end if/else
$(document).trigger("select-state-change", {
State: checkbox.customSelect.State,
Target: $("#select-all")
});
});
$("input[name='options']").each(function () {
$(this).click(function () {
if ($(this).prop("checked") == true) {
$(document).trigger("item-selected", {
IsSelected: true
});
if ($(this).parent().parent().find("input[type='checkbox']:checked").length == $(this).parent().parent().find("input[type='checkbox']").length) {
$(document).trigger("select-state-change", {
State: 2,
Target: $("#select-all")
});
} else {
$(document).trigger("select-state-change", {
State: 1,
Target: $("#select-all")
});
} // end if/else
} else {
$(document).trigger("item-selected", {
IsSelected: false
});
if ($(this).parent().parent().find("input[type='checkbox']:checked").length <= 0) {
$(document).trigger("select-state-change", {
State: 0,
Target: $("#select-all")
});
} else {
$(document).trigger("select-state-change", {
State: 1,
Target: $("#select-all")
});
} // end if/else
} // end if/else
});
});
});
body {
font-family: Helvetica, Verdana, Sans-Serif;
font-size: small;
color: #232323;
background-color: #efefef;
padding: 0px;
margin: 0px;
}
H1 {
margin-top: 2px;
text-align: center;
}
LEGEND {
margin-bottom: 6px;
}
.content-wrapper {
padding: 2px;
margin: 3px auto;
width: 100%;
max-width: 500px;
min-width: 250px;
}
.wrapper {
padding: 3px;
margin: 2px;
}
.container {
border-right: solid 1px #788967;
border-bottom: solid 1px #677867;
border-top: solid 1px #89ab89;
border-left: solid 1px #89ab89;
}
.rounded {
border-radius: 2px;
}
.contents {
background: linear-gradient(rgba(255, 255, 255, 1), rgba(180, 180, 180, .2));
}
.header {
padding: 4px;
border: solid 1px #000000;
background-color: rgba(200, 200, 230, .8);
font-size: 123%;
background-image: linear-gradient(rgba(220, 220, 255, .8), rgba(200, 200, 230, .8));
}
#options-chooser {
margin-top: 30px;
display: block;
}
#options-chooser .options-list > LABEL {
display: table-row;
height: 26px;
}
.red {
color: red;
}
.blue {
color: blue;
}
.green {
color: green;
}
.black {
color: black;
}
.options-status {
float: right;
right: 3%;
clear: both;
display: none;
margin-top: -20px;
}
.output {
font-weight: bold;
}
.not-there {
border-color: rgba(190, 190, 190, .3);
background-color: rgba(190, 190, 190, .1);
}
.almost-there {
border-color: rgba(220, 220, 50, .6);
background-color: rgba(220, 220, 50, .3);
}
.finally-there {
border-color: rgba(50, 190, 50, .3);
background-color: rgba(50, 190, 50, .1);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js"></script>
<div class="content-wrapper">
<div class="wrapper container rounded">
<div class="contents">
<h1 class="header rounded">Partial Select All Example</h1>
<p>This example demonstrates how to implement a tri-state checkbox with options.</p>
<form name="options-chooser" id="options-chooser" method="post">
<fieldset class="rounded options">
<legend class="rounded header">Options
<input type="checkbox" value="options-all" name="selectAll" id="select-all" title="Select All" />
</legend> <span class="options-status rounded container wrapper">Items Selected: <span class="output"></span></span>
<div class="options-list">
<label class="blue">
<input type="checkbox" name="options" value="1" />Blue</label>
<label class="green">
<input type="checkbox" name="options" value="2" />Green</label>
<label class="red">
<input type="checkbox" name="options" value="3" />Red</label>
<label class="black">
<input type="checkbox" name="options" value="4" />Black</label>
</div>
</fieldset>
</form>
</div>
</div>
</div>
मैं एक समाधान एक देशी चेकबॉक्स और अनिश्चित संपत्ति का उपयोग कर और चेकबॉक्स में एक कस्टम विशेषता भंडारण के लिए एक प्रभावी ट्रिपल राज्य चेकबॉक्स प्राप्त करने के लिए वर्तमान स्थिति पर कब्जा करने की है।
यह समाधान लिनक्स और IE 11, फायरफॉक्स और क्रोम Windohs पर पर नवीनतम Chrome और Firefox और क्रोमियम (nw.js) पर अच्छी तरह से बाहर का परीक्षण किया है।
मैं के लिए इस समाधान को तैनात किया है JSFiddle ।
यहाँ उपयोगिता सिंगलटन मैं प्रयोग किया जाता है:
tscb$ = {
STATE_UNCHECKED: 0
,STATE_CHECKED: 1
,STATE_INDETER: 2
,setState: function(o,iState){
var t=this;
if(iState==t.STATE_UNCHECKED){
o.indeterminate=false; o.checked=false;
} else if(iState==t.STATE_CHECKED){
o.indeterminate=false; o.checked=true;
} else if(iState==t.STATE_INDETER){
o.checked=false; o.indeterminate=true;
} else {
throw new Error("Invalid state passed: `"+iState+"`")
}
o.setAttribute("tscbState", iState);
}
// Event to call when the cb is clicked to toggle setting.
,toggleOnClick: function(o){
var t=this, iNextState=t.getNextState(o)
if(iNextState==t.STATE_UNCHECKED){
o.checked=false;
} else if(iNextState==t.STATE_CHECKED){
o.checked=true;
} else if(iNextState==t.STATE_INDETER){
o.indeterminate=true;
}
o.setAttribute("tscbState", iNextState);
}
// For retrieval of next state
,getNextState: function(o){
var t=this, iState=t.getState(o)
if(iState==t.STATE_UNCHECKED){
return t.STATE_INDETER;
} else if(iState==t.STATE_CHECKED){
return t.STATE_UNCHECKED;
} else if(iState==t.STATE_INDETER){
return t.STATE_CHECKED;
}
}
,getState: function(o){
return parseInt(o.getAttribute("tscbState"))
}
}
उपयोग:
अपनी अद्भुत कैसे प्रभावी एक ट्रिपल राज्य चेकबॉक्स एक यूआई कॉम्पैक्ट रखने में किया जा सकता है, जबकि अद्वितीय छानने कार्यक्षमता के लिए अनुमति देता है। इसके गतिशील खोज परिणाम फ़िल्टर करने के लिए बहुत प्रभावी है, जहां एक फिल्टर सही / गलत / सिर्फ एक नियंत्रण के साथ बंद हो सकता है