Kendo multiselect enable summary tag mode after a few selections are made - kendo-asp.net-mvc

I have a kendo multiselect i have set up in summary tag mode with this template:
# if (dataItems.length < 4) { #
# for (var idx = 0; idx < values.length; idx++) {#
#:dataItems[idx].Name#
# if (idx < values.length - 1) {#</li><li class="k-button" unselectable="on"> # } #
#}#
# } else {#
#:values.length# item(s) selected
# } #
This works but it's hacky. What it does is show the first few entries and then group them if you choose four or more. The kendo ui version of this control has a property that allows what i want to do here to work automatically. [kendoMultiSelectSummaryTag]="3"
However that property doesn't seem to be available unless i'm looking in the wrong spot. Can someone tell me how to use it? I would like the default functionality to work because that allows deletions from the selection display.

As far as I can tell there isn't a simple property you can set that will do this for you. Fortunately the solution isn't too tricky. The idea will be to set the default tagMode to 'multiple' (which is it by default), then to create an event handler which will change the tagMode to 'single' when the number of items is crosses your threshold.
Your multiselect definition will need to attach the event handler to the change event:
#(Html.Kendo().MultiSelect()
.Name("multiSelect")
// other properties as needed of course
.Events(events => events
.Change("tagModeSet")
)
)
The javascript event handler will then look something like this:
function tagModeSet() {
// Get the currently selected values and tagMode
var selectedValues = this.value();
var currentTagMode = this.options.tagMode;
var newTagMode = currentTagMode;
// Test to see if you have crossed the threshold
if (selectedValues.length <= 3) {
newTagMode = "multiple";
} else {
newTagMode = "single"
}
// Update the tagMode if needed
if (newTagMode != currentTagMode) {
this.value([]);
this.setOptions({
tagMode: newTagMode
});
this.value(selectedValues);
}
}
Note that when you update the tagMode you first clear the items, then adjust the mode, then re-select the items. Hope that helps.
Reference

Related

Apex5, tick all and untick all checkbox

I want a checkbox in an Interactive Report (IR), and I want the users to be able to quickly Select All or Unselect All of them with a single checkbox in the header.
Added java scripted code but it's not working any idea .....
if ( $( '#selectunselectall' ).is(':checked') ) {
$('input[type=checkbox][name=f01]').attr('checked',true);
Else
$('input[type=checkbox][name=f01]').attr('checked',false);
Add the checkbox to the query, e.g. apex_item.checkbox(1, record_id) as selected.
Set the region Static ID to some value, e.g. myreport
Set the following attributes of column “SELECTED”:
Heading = <input type="checkbox" id="selectunselectall">
Escape Special Characters = No
Enable Users To = (uncheck all options, including Hide, Sort, etc.)
Add a Dynamic Action:
Event = Change
Selection Type = jQuery Selector
jQuery Selector = #selectunselectall
Event Scope = Dynamic
Static Container (jQuery Selector) = #myreport
True Action = Execute JavaScript Code
Fire On Page Load = No
Code =
if ($( '#myreport #selectunselectall' ).is(':checked')) {
$('#myreport input[type=checkbox][name=f01]').attr('checked',true);
} else {
$('#myreport input[type=checkbox][name=f01]').attr('checked',false);
}
Amendment made to jeff's code:
if ($( '#myreport #selectunselectall' ).is(':checked')) {
$('#myreport input[type=checkbox][name=f01]').prop('checked',true);
} else {
$('#myreport input[type=checkbox][name=f01]').prop('checked',false);
}
jQuery API - .prop()
Jeff Kemp's select/unselect all
Have a look at the above link. Jeff Kemp has done a great job documenting your objective.

Sitecore, render Item in code with personalization in mvc

My terminology might be slightly off as I am new to Sitecore mvc. I am trying to hardcode a view rendering with a hard coded datasource (I have to do it this way for other requirements) This view rendering has placeholders that are dynamically set and then personalized.
How can I trigger the ViewRendering on an item?
I've tried ItemRendering, but it doesn't seem to be picking up the stuff set up in the PageEditor.
* To be clear, the helpful posts below have the rendering working, but we do not seem to be getting the personalized datasources. *
I believe this is what you're after:
Item item = /* think you already have this */;
// Setup
var rendering = new Sitecore.Mvc.Presentation.Rendering {
RenderingType = "Item",
Renderer = new Sitecore.Mvc.Presentation.ItemRenderer.ItemRenderer {
Item = item
}
};
rendering["DataSource"] = item.ID.ToString();
// Execution
var writer = new System.IO.StringWriter();
var args = new Sitecore.Mvc.Pipelines.Response.RenderRendering(rendering, writer);
Sitecore.Mvc.Pipelines.PipelineService.Get().RunPipeline("mvc.renderRendering", args);
// Your result:
var html = writer.ToString();
You can statically bind a View Rendering using the Rendering() method of the Sitecore HTML Helper. This also works for Controller Renderings using the same method.
#Html.Sitecore().Rendering("<rendering item id>")
This method accepts an anonymous object for passing in parameters, such as the Datasource and caching options.
#Html.Sitecore().Rendering("<rendering item id>", new { DataSource = "<datasource item id>", Cacheable = true, Cache_VaryByData = true })
In your view rendering, I am assuming you have a placeholder defined along with the appropriate placeholder settings in Sitecore (If not, feel free to comment with more detail and I will update my answer).
#Html.Sitecore().Placeholder("my-placeholder")
In this case, "my-placeholder" will be handled like any other placeholder, so you will be able to add and personalize components within it from the Page Editor.

Set focus to a column filter in an Infragistics WebDataGrid

I am using an Infragistics NetAdvantage WebDataGrid with filtering set.
On page load, I would like to open the first filter’s textbox, and set the focus there, so that it is ready for the user to start typing the text with which to filter.
I have seen an example online of how to do this for the jQuery grid, but not for the WebDataGrid
I want something along the lines of:
myWebDataGrid.Behaviors.Filtering.ColumnFilters[2].RuleTextNode.focus;
I am using Infragistics35.Web.v11.2, Version=11.2.20112.2025
To do this you can call enterEditMode on the filter row when your page loads, passing in the specific cell you want edit:
function enterEditFilter() {
var grid = $find('<%= grid.ClientID %>');
var filtering = grid.get_behaviors().get_filtering();
var filterRow = filtering._row;
var cell = filterRow.get_cellByColumnKey('Text');
filtering.enterEditMode(cell);
}
Please note that to do this you have to be able to get access to the filter row. It doesn't appear that there is a way to access this through the public API so I use the private variable _row. This is not a recommended approach as that variable may change, so I suggest that you submit a new product idea to have the filter row added to the public API. You can do this on the following page:
http://ideas.infragistics.com/
Another thing to note is that the default filter type is "All" so you'll also want to change this. You can do this by handling the client side filtering event and setting the rule there:
function grid_filtering(sender, eventArgs) {
var filters = eventArgs.get_columnFilters();
for (var i = 0; i < filters.length; i++) {
var condition = filters[i].get_condition();
if (condition.get_rule() === 0) {
var columnType = filters[i].get_columnType();
if (columnType == 'string') {
condition.set_rule($IG.TextFilterRules.Equals);
}
else if (columnType == 'number') {
condition.set_rule($IG.NumericFilterRules.Equals);
}
}
}
}

Insert more records at once in raw_id_fields

I have a m2m relation where in my AdminForm I would use raw_id_fields instead of the filter_horizontal option. For explanation I prefer the raw_id_fields instead of the filter_horizontal option, because the records are already categorized. So in the popup-window the user has the ability to search and filter via category.
But there are two points that I can't figure out:
possibility to selecting more than one record in the popup window
showing the real names instead of the pk in the input_field
It's possible. In order to select more than one record, you need to override default dismissRelatedLookupPopup() in django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js by including your script in the Media class of your ModelAdmin or widget:
var dismissRelatedLookupPopup = (function(prev, $) {
return function(win, chosenId) {
var name = windowname_to_id(win.name);
var elem = document.getElementById(name);
// 1. you could add extra condition checking here, for example
if ($(elem).hasClass('my_raw_id_ext_cls')) { // add this class to the field
// ...logic of inserting picked items from the popup page
}
else { // default logic
prev(win, chosenId);
}
// 2. or you could copy the following part from RelatedObjectLookups.js ...
if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
elem.value += ',' + chosenId;
// 2. and add a return. Remember this acts globally.
return;
} else {
document.getElementById(name).value = chosenId;
}
// 3. the following line cause the popup to be closed while one item is picked.
// You could comment it out, but this would also affect the behavior of picking FK items.
win.close();
}
})(dismissRelatedLookupPopup, django.jQuery);
Django does not support this by default. There are some snippets at djangosnippets.org, you may want to take a look at them.
Finally I'm using a modified https://django-salmonella.readthedocs.org/en/latest/. I don't show the input field and show the selected records in a table.

How do I utilize the save event in a Sitecore custom Item Editor?

I am creating a custom item editor, and am using the following blog post as a reference for responding to the "save" event in the Content Editor, so that I do not need to create a second, confusing Save button for my users.
http://www.markvanaalst.com/sitecore/creating-a-item-editor/
I am able to save my values to the item, but the values in the normal Content tab are also being saved, overriding my values. I have confirmed this via Firebug. Is there a way to prevent this, or to ensure my save is always after the default save?
I have this in as a support ticket and on SDN as well, but wondering what the SO community can come up with.
Thanks!
Took a shot at an iframe-based solution, which uses an IFrame field to read and save the values being entered in my item editor. It needs to be cleaned up a bit, and feels like an interface hack, but it seems to be working at the moment.
In my item editor:
jQuery(function () {
var parentScForm = window.parent.scForm;
parentScForm.myItemEditor = window;
});
function myGetValue(field) {
var values = [];
jQuery('#myForm input[#name="' + field + '"]:checked').each(function () {
values.push(jQuery(this).val());
});
var value = values.join('|');
return value;
}
In my Iframe field:
function scGetFrameValue() {
var parentScForm = window.parent.scForm;
if (typeof (parentScForm.myItemEditor) != "undefined") {
if (typeof (parentScForm.myItemEditor.myGetValue) != "undefined") {
return parentScForm.myItemEditor.myGetValue("myLists");
}
}
return null;
}
In theory, I could have multiple fields on the item which are "delegated" to the item editor in this way -- working with the content editor save rather than trying to fight against it. I'm a little uneasy about "hitchhiking" onto the scForm to communicate between my pages -- might consult with our resident Javascript hacker on a better method.
Any comments on the solution?
EDIT: Blogged more about this solution