Selecting the kendo grid row on DetailExpand event - kendo-ui

I've got a Kendo grid with detail template. When I open the detail template, I want the respective row to be selected. By default, the detail expands but the row isn't selected.
.Events(e => e.Change("onChange").DetailExpand("jsFunction"))
I know there's a DetailExpand event that fires when the detail is expanded, I just don't know how to make it select the row to which it refers. I have tried:
function jsFunction() {
this.dataItem(this.select()); <--- breaks here because there's no row selected
}
How can I make it select the row?

Nothing is easier:
function jsFunction(e) {
e.sender.select(e.masterRow);
}
Grettings.

Related

Slickgrid select row on right click before displaying context menu

Using this I can display a menu by right clicking a cell:
// right click context menu
grid.onContextMenu.subscribe(function (e) {
e.preventDefault();
var cell = grid.getCellFromEvent(e);
//grid.setSelectedRows(cell.row);
$("#contextMenu")
.data("row", cell.row)
.css("top", e.pageY)
.css("left", e.pageX)
.show();
$("body").one("click", function () {
$("#contextMenu").hide();
});
});
However I would like the row to be selected, both as visual confirmation that the correct row has been right-clicked, and because some of the menu items use the selected row for their functions.
This:
grid.setSelectedRows(cell.row);
doesn't work. What is the correct way?
It might be as simple as the fact that setSelectedRows takes an array of row indexes.
Try
grid.setSelectedRows([cell.row]);

Kendo cascading dropdown loading dropdown based on other drop down selection

I am planning of using a cascading kendo drop down.
Drop down 1 - Countries - it will list down all the countries.
Drop down 2 - States - Based on the selection of the country I have to show the states here.
The data for both are loaded from my api controllers. I referred to this link
http://demos.kendoui.com/web/dropdownlist/cascadingdropdownlist.html
But, I need to pass the first selected value to the second drop down.
PLease suggest the best way to do it. Examples would be really helpful.
Thanks.
you have to use events for that
http://demos.kendoui.com/web/dropdownlist/events.html
.Events(e =>
{
e.Change("change").Select("select").Open("open").Close("close").DataBound("dataBound");
})
<script>
function change() {
// get a reference to the dropdown list
var dropdownlist = $("#dropdownlistTwoForStates").data("kendoDropDownList");
//Write your logic here to bind data for thie dropdown
// disable the dropdown list
dropdownlist.enable(true);
};
</script>

How to delete multiple rows in Kendo grid?

I have a kendo grid with first column as Checkboxes. I want to delete multiple rows using those check boxes. I am able to delete only single row at a time.
I tried adding
.Batch(true)
for the data source and below is my function for delete button outside the grid.
function deleteRule() {
var grid = $("#grid").data("kendoGrid");
grid.select().each(function () {
grid.removeRow($(this));
});
}
Any suggestions please ?
Yo mate,
How exactly do you remove that one row? Why you use the select method?
Basically I would suggest you to create a delete button which executes the logic to delete the selected rows - I guess you are using a tempalte column with a checkbox inside. If you add a class to that checkbox you can easily select all the checkboxes inside of the grid. So lets say the name of the class for the checkbox is cool then you can execute the following logic in the delete button click handler:
function whenYourDeleteButtonIsClicked(){
var grid = $("#grid").data("kendoGrid");
$('.cool:selected').each(function(){
grid.removeRow($(this).closest('tr'));
})
}
I hope you got the idea mate.
Good luck.
Here is what i use
works very well
$('#your-grid-id').data("kendoGrid").select().each(function () {
grid.dataSource.remove(grid.dataItem($(this).closest("tr")));
});

jqGrid multiselect - limit the selection of the row only using the checkbox

Good morning, I'm working on a jqGrid that have the multiselection active.
I need to limit the selection of the row only using the multisel box, not by clicking everywhere on the row.
Thats's because I need to do some action by clicking links on some cells and I won't alter the active multiselection.
I tried to set the multiboxonly property, but it's not what I need.
I didn't find anything else to customize this function of the grid.
You can control on which click the row will be selected with respect of your custom beforeSelectRow event handler. If the handler return true, the row will be selected. If you return false the row will be not selected.
The second parameter of beforeSelectRow is event object, e.target is the DOM element which was clicked. You can get the cell (<td>) in which the click done with $(e.target).closest('td'). Then you can use $.jgrid.getCellIndex to get the index of the cell insido of the row. The index in the colModel should point to the 'cb' column which contain the checkboxes. So the code could be the following:
beforeSelectRow: function (rowid, e) {
var $myGrid = $(this),
i = $.jgrid.getCellIndex($(e.target).closest('td')[0]),
cm = $myGrid.jqGrid('getGridParam', 'colModel');
return (cm[i].name === 'cb');
}
The corresponding demo you can see here.
I would like to suggest easier solution:
beforeSelectRow: function(rowid, e) {
return $(e.target).is('input[type=checkbox]');
},
When multiselect is set to true, clicking anywhere on a row selects that row; when multiboxonly is also set to true, the multiselection is done only when the checkbox is clicked.
So the answer would be:
multiboxonly: true

jqgrid check before clicking add button

for a treegrid i want to enable the add button only if a record is selected. if that is not possible on clicking the add button i would like to see if the rowid selected is not null.
Any ideas i tried the beforeshowform i could not figure out how to skip adding the form.
beforeShowForm: function(formid) {
var rowid = jQuery("#treegrid").getGridParam('selrow');
if(rowid == null ) {
return[false,"Please select a row."];
} else {
return[true,""];
}
}
Please help!
In the old answer I created the demo. In the demo I made the first row 'not-editable-row' so the "Add" and "Edit" buttons from the navigation bar will be disabled on the row selection. If one selects the second row the "Add" and "Edit" buttons will be enabled. If one unselect the row, so no rows are selected the "Add" and "Edit" buttons will be disabled one more time.
You can use the same idea in case of the treegrid.

Resources