Create custom command to expand client detail template in Kendo UI Grid (MVC) - asp.net-mvc-4

I've got a nested grid within my grid, and it works perfectly, but the client doesn't like to use the arrow on the left and asked for a button to be added in order to show the child grid.
The example on the Kendo website shows how to automatically open the first row, I just want a way to expand the grid from a custom control in the same way that the left selector does it.
I've got the custom command working, and it executes the sample code, but I just need some help with the javascript required to make it work for the current row.
columns.Command(command =>
{
command.Edit().Text("Edit").UpdateText("Save");
command.Destroy().Text("Del");
command.Custom("Manage Brands").Click("showBrandsForAgency");
And the js with the standard example of opening the first row:
function showBrandsForAgency(e) {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
Please help by giving me the js required to expand the row clicked and not the first row?
* EDIT *
Modified the solution provided by Atanas Korchev in order to get it to work on only the button and not the whole row.
I'd prefer a solution that uses the function showBrandsForAgency instead of a custom funciton but this does the job:
$(document).ready(function () {
$("#grid").on("click", "a", function (e) {
var grid = $("#grid").data("kendoGrid");
var row = $(this).parent().parent();
if (row.find(".k-icon").hasClass("k-minus")) {
grid.collapseRow(row);
} else {
grid.expandRow(row);
}
});
});

You can try something like this:
$("#grid").on("click", "tr", function(e) {
var grid = $("#grid").data("kendoGrid");
if ($(this).find(".k-icon").hasClass("k-minus")) {
grid.collapseRow(this);
} else {
grid.expandRow(this);
}
});
When using jQuery on the function context (available via the this keyword) is the DOM element which fired the event. In this case this is the clicked table row.
Here is a live demo: http://jsbin.com/emufax/1/edit

Same results just Simpler, faster, and more efficient:
$("#grid").on("click", "tr", function () {
$(this).find("td.k-hierarchy-cell .k-icon").click();
});

Related

How to show a report with dynamic parameters from a chart on Pentaho?

I have a pie chart on my dashboard, using click action, I menaged to show a report that has one fixed parameter. Here is my JS function on click action:
function showreport(scene) {
var newWindow;
if(scene.getCategory()=='POS'){
newWindow=window.open("url_report?type_lm=POS", 'REPORT');
}else{
newWindow=window.open("url_report?type_lm=NEG", 'REPORT');
}
}
This one works fine.
But now I want to pass a dynamic parameter too ( the variable obtained with query component, it is stocked in result var (code_lm):
Here is what I did:
function showreport(scene) {
var newWindow;
var code_lm=this.dashboard.getParameterValue('code_lm');
if(scene.getCategory()=='POS'){
newWindow=window.open("url_report?type_lm=POS&code="+code_lm, 'REPORT');
}else{
newWindow=window.open("url_report?type_lm=NEG&code="+code_lm, 'REPORT');
}
}
This one doesn't work, nothing is displayed by clicking the chart. I found this line var code_lm=this.dashboard.getParameterValue('code_lm'); causes the prob.
However, I do the same thing with button component :
function showreport() {
var code_lm=this.dashboard.getParameterValue('code_lm');
var newWindow = window.open("url_report?code=" + code_lm,'REPORT');
}
and it works perfectly so I wonder why this.dashboard.getParameterValue() is not working in some cases.
Can anyone tell me where comes from the problem ?
yes, if you want to pass value of parameter from query component then you need set parameter value by writing bellow code in post fetch of query component.
function fun(code_lm) {
dashboard.setParam('yourParamName',code_lm.resultset);
}
check out this may help you. How to pass a variable obtained from query component into a query on Pentaho CDE? may help you.

Bootstrap 3 collapse with javascript not working

When I'm using Javascript options for collapse, the toggle doesn't work. It only opens first time the panel.
This one works well - $('#login').collapse('toggle')
But I want to add more options like parent.
http://www.bootply.com/DFfPmKnDTd#
this code can be help...
$('#login').collapse({
toggle : true,
parent : '#accordion'
});
$('#c1').on('click', function(){
$('#login').collapse('toggle');
}
);
First you need to initiate collapse function and then make call to toggle it.
Then you need to initialize each collapse link.
Try using by using this code may be it can work for target link.
$.each($('#accordion .accordion-toggle'), function(index, collapse_link)
{
var $collapse = $('#collapse_element_id'+element_no); // you need to right here '#c'+element_id ( it will take #c1, #c2 , #c3 )
$collapse.collapse({
toggle : true,
parent : '#accordion'
});
$(collapse_link).on('click', function(){
$collapse.collapse('toggle');
});
});

cannot preserve values in the textbox after dropdown on change event

I have a problem in preserving the values in the textbox after dropdownlist selected index changed in asp.net mvc. Below is the code for initiating the dropdown onchange event.
#Html.DropDownList("BranchId",null,"Select Branch", new { onchange = "location.href='/User/GetRoles?BranchId='+this.options[this.selectedIndex].value" })
Аnd the roles dropdown binded with the values, but what i typed in the textboxes just above the branch dropdown get lost.
Please help me.
Regards,
Azeem
This is because you are changing your URL location by using location.href. What exactly do you want to achieve? If you need to load certain logic, you might as well bind change event to jQuery function that could load data from the server, and then you do something with that data.
$(document).ready(function() {
$("#BranchId").change(function() {
$.getJSON(YourUrlThatReturnsValues, {data: yourparameter}, function() {
// do some processing here.
});
});
});
The other option is to use Ajax Helpers instead of Html Helpers. Instead of Html.DropDownList you would use Ajax.DropDownList.
You may try something like that:
$(function () {
$('#BranchId').change(function () {
var id = $("#BranchId option:selected").val();
var data = {BranchId: id };
$.get("#Url.Action("User", "GetRoles")", data).done(function(d){
$('.somediv').val(d.rolename)
});
});

Calling member functions on click/tap within sencha touch 2 templates

I am rather new to sencha touch, I've done a lot of research and tutorials to learn the basics but now that I am experimenting I have run into a problem that I can't figure out.
I have a basic DataList which gets its data from a store which displays in a xtemplate.
Within this template I have created a member function which requires store field data to be parsed as a parameter.
I would like to make a thumbnail image (that's source is pulled from the store) execute the member function on click/tap.
I can't find any information on this within the docs, does anyone know the best way to go about this?
Here is a code example (pulled from docs as I can't access my actual code right now).
var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>'
{
tapFunction: function(name){
alert(name);
}
}
);
tpl.overwrite(panel.body, data);
I want to make the paragraph clickable which will then execute the tapFunction() member function and pass the {name} variable.
Doing something like onclick="{[this.tapFunction(values.name)]} " does not seem to work.
I think functions in template are executed as soon as the view is rendered so I don't think this is the proper solution.
What I would do in your case is :
Add a unique class to your < p > tag
tpl : '<p class="my-p-tag">{name}</p>'
Detect the itemtap event on the list
In your dataview controller, you add an tap event listener on your list.
refs: {
myList: 'WHATEVER_REFERENCE_MATCHES_YOUR_LIST'
},
control: {
myList: {
itemtap: 'listItemTap'
}
}
Check if the target of the tap is the < p > tag
To do so, implement your listItemTap function like so :
listItemTap: function(list,index,target,record,e){
var node = e.target;
if (node.className && node.className.indexOf('my-p-tag') > -1) {
console.log(record.get('name'));
}
}
Hope this helps

Simple store connected list for dojo

Is there a simpler list type than DataGrid that can be connected to a store for Dojo?
I would like the data abstraction of the store, but I don't need the header and cell stucture. I would like to be more flexible in the representation of the datalines, where maybe each line calls an function to get laid out...
You ask a really good question. I actually have a blog post that is still in draft form called "The DataGrid should not be your first option".
I have done a couple thing using the store to display data from a store in a repeated form.
I have manually built an html table using dom-construct and for each.
var table = dojo.create('table', {}, parentNode);
var tbody = dojo.create('tbody', {}, table); // a version of IE needs this or it won't render the table
store.fetch({ // this is a dojo.data.ItemFileReadStore, but you cana dapt to the dojo.Store API
query: {},
onComplete: function(itms) {
dojo.forEach(itms, function(itm, idx) {
var tr = dojo.create('tr', {}, tbody);
// use idx to set odd/even css class
// create tds and the data that goes in them
});
}
});
I have also created a repeater, where I have an html template in a string form and use that to instantiate html for each row.
var htmlTemplate = '<div>${name}</div>'; // assumes name is in the data item
store.fetch({ // this is a dojo.data.ItemFileReadStore, but you cana dapt to the dojo.Store API
query: {},
onComplete: function(itms) {
dojo.forEach(itms, function(itm, idx) {
var expandedHtml = dojo.replace(htmlTemplate, itm);
// use dojo.place to put the html where you want it
});
}
});
You could also have a widget that you instantiate for each item.