Ways to deactivate Kendo UI draggable function

While working in my Angular-Kendo setup, I have implemented a Drag/Drop functionality on the rows of two grids.

I referred to this example as the basis for my code : http://jsfiddle.net/BtkCf/4/

The row drag feature is functioning properly, but it seems to be conflicting with the ROW EDIT functionality.

How can I disable this during row editing? I attempted the following in my grid code:

  $('#userKriGrid tbody tr').off();

However, I am still unable to access the row text when editing.

I am looking for guidance on how to better manage these CLICK() events - specifically, enabling and disabling them as required.

This is the HTML definition of the "userKriGrid" grid:

 <span id="userKriGrid"  
  kendo-grid="vm.userKriGrid" 
  k-data-source="vm.kriUserGridDS"
 k-options="vm.userKriGridOptions" 
  k-rebind="vm.userKriGridOptions">
 </span>

The JavaScript code for setting up the "userKriGrid" grid options :

 vm.userKriGridOptions = {   // Kendo grid - USER KRI...
        selectable: true,
        sortable: true,
        pageable: true,
        resizable: true,
        columns: [
          { field: "id",  width: "10px", hidden: true },
          { field: "kri_group", width: "100px" },
          { field: "kri", width: "110px" },
          { field: "kri_alias", title: "Column Alias", width: "80px" },
          { field: "aggreg_formula", title:"formu", width: "170px", hidden: false },
          { command: [{ name: "edit", text: '' }, { name: "destroy", text: '' }], width: 140 }
        ],
        editable: "inline",
        confirmation: false,            
        toolbar: ["create"],
        edit: function(e){
            $('#userKriGrid tbody tr').off();  // ATTEMPT TO TURN OFF CLICK EVENT !
        },
        messages: {
            commands: {
                cancel: "Cancel",
                canceledit: "Cancel",
                create: "kri",
                destroy: "Delete",
                edit: "Edit",
                save: "Save changes",
                select: "Select",
                update: "Update"
            }
        }
    };   

Further adding the Kendo created listener for both grids:

    // ADD LISTENER TO KENDO GRID CREATED EVENT
    $scope.$on("kendoWidgetCreated", function (ev, widget) {
        if (widget.element[0].id == "userDimenGrid"){                
            addDragDropDimenGridRow();                
        }
        if (widget.element[0].id == "userKriGrid") {
            addDragDropKRIGridRow();
        }
    });

Here's a screen shot showing the EDIT button on a row (from the "userKriGrid")

Another screen shot after clicking on the EDIT icon - now unable to click and modify the text !

Lastly, the DOM event code for enabling drag/drop functionality of a grid row:

  function addDragDropKRIGridRow() {
        var mainGrid = $("#userKriGrid").data("kendoGrid");
        var mainDataSource = vm.kriUserGridDS;
        var selectedClass = 'k-state-selected';

        if (mainGrid == undefined) {
            return;
        }

        $.fn.reverse = [].reverse;

        $(document).on('click', '#userKriGrid tbody tr', function (e) {
            if (e.ctrlKey || e.metaKey) {
                $(this).toggleClass(selectedClass);
            } else {
                $(this).addClass(selectedClass).siblings().removeClass(selectedClass);
            }
        });

        mainGrid.table.kendoDraggable({
            filter: "tbody tr",
            group: "gridGroup",
            axis: "y",
            hint: function (item) {
                var helper = $('<div class="k-grid k-widget drag-helper"/>');
                if (!item.hasClass(selectedClass)) {
                    item.addClass(selectedClass).siblings().removeClass(selectedClass);
                }
                var elements = item.parent().children('.' + selectedClass).clone();
                item.data('multidrag', elements).siblings('.' + selectedClass).remove();
                return helper.append(elements);
            }
        });
        mainGrid.table.kendoDropTarget({
            group: "gridGroup",
            drop: function (e) {

                var draggedRows = e.draggable.hint.find("tr");
                e.draggable.hint.hide();
                var dropLocation = $(document.elementFromPoint(e.clientX, e.clientY)),
                    dropGridRecord = mainDataSource.getByUid(dropLocation.parent().attr("data-uid"))
                if (dropLocation.is("th")) {
                    return;
                }

                var beginningRangePosition = mainDataSource.indexOf(dropGridRecord),
                    rangeLimit = mainDataSource.indexOf(mainDataSource.getByUid(draggedRows.first().attr("data-uid")));

                if (rangeLimit > beginningRangePosition) {
                    draggedRows.reverse();
                }

                draggedRows.each(function () {
                    var thisUid = $(this).attr("data-uid"),
                        itemToMove = mainDataSource.getByUid(thisUid);
                    mainDataSource.remove(itemToMove);
                    mainDataSource.insert(beginningRangePosition, itemToMove);
                });

                draggedRows.each(function () {
                    var thisUid = $(this).attr("data-uid");
                    mainDataSource.getByUid(thisUid).set("dirty", true);
                });

                var dirtyItems = $.grep(mainDataSource.view(), function (e) { return e.dirty === true; });
                for (var a = 0; a < dirtyItems.length; a++) {
                    var thisItem = dirtyItems[a];
                    mainGrid.tbody.find("tr[data-uid='" + thisItem.get("uid") + "']").find("td:eq(0)").addClass("k-dirty-cell");
                    mainGrid.tbody.find("tr[data-uid='" + thisItem.get("uid") + "']").find("td:eq(0)").prepend('<span class="k-dirty"></span>')
                };
            }
        });
    }

Answer №1

Currently in the process of figuring this out myself - came across this helpful resource: http://docs.telerik.com/kendo-ui/web/sortable/overview#sortable-items-with-inputs

update: seems to be related to this issue as well - Cannot select text in Kendo Sortable with handle

update: I managed to solve this by configuring kendoSortable() with the following settings:

 start: function(e){ 
    if($('#wims-grid-actionstep').find('.k-grid-edit-row').length > 0){      
                                           e.preventDefault(); return false;}
    },
ignore: ".k-grid-edit-row *",

The start event prevents selection in all rows when the grid is being edited, and the ignore option allows for selecting the edit boxes within my edit row.

Answer №2

Adding onto the response from user2983931, I have my own solution that also handles sortable grid rows.

It's important to note that the filter option is crucial for ignoring the edit-row features of the Kendo grid. Without it, the inner text becomes uneditable.

Here is an Angular listener implementation:

// Attaching a listener to the Kendo grid created event
$scope.$on("kendoWidgetCreated", function (ev, widget) {
    if (widget.element[0].id == "userKriGrid") {
        kendoSortableGrid("KRI");
    }
});

function kendoSortableGrid(gridtype) {
    grid.table.kendoSortable({
        filter: ">tbody >tr:not(.k-grid-edit-row)",
        hint: $.noop,
        cursor: "move",
        ignore: "input",
        placeholder: function (element) {
            return element.clone().addClass("k-state-hover").css("opacity", 0.65);
        },
        container: cont,
        change: function (e) {
            var skip = grid.dataSource.skip(),
                oldIndex = e.oldIndex + skip,
                newIndex = e.newIndex + skip,
                data = grid.dataSource.data(),
                dataItem = grid.dataSource.getByUid(e.item.data("uid"));

            grid.dataSource.remove(dataItem);
            grid.dataSource.insert(newIndex, dataItem);
        }
    });
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Maintaining the order of elements in Angular's insertion process

I am currently facing an issue with my HTML fragment that iterates over a key and value collection. Everything works perfectly when I insert values into an object and iterate through it using the HTML fragment. However, in order to maintain a specific key ...

When placed above in the template, the ng-model is causing the ng-repeat to not display anything

Currently, I am teaching myself Angular by following a tutorial at https://docs.angularjs.org/tutorial, but with my twist of using different data to keep things interesting. My struggle seems to stem from a simple mistake I might be making, compounded by ...

retrieve the height value of a div element using AngularJS

I'm having trouble retrieving the updated height of a div using AngularJS. It seems to only provide the initial value and does not update as expected: vm.summaryHeight = $(".history-log-container").height(); console.log(vm.summaryHeight);//always dis ...

Using AngularJS to populate dropdown options with data from JSON objects

I have a JSON file that looks like this: var myJson = { "Number of Devices":2, "Block Devices":{ "bdev0":{ "Backend_Device_Path":"/dev/ram1", "Capacity":"16777216", "Bytes_Written":9848, "timestamp":"4365093 ...

Insert the ng-if directive into an element using a directive

I am working on an AngularJS directive that involves looking up col-width, hide-state, and order properties for a flexbox element based on its ID. I want to dynamically add an ng-if=false attribute to the element if its hide-state is true. Is there a way ...

Invalid mime type for HTML5 mode

I have successfully set up my redirect, but now all my style sheets are being served as text/html because they are going through core.index. Strangely, I only get this error for style sheets and not for JS files. How can I fix this issue? Error: Res ...

In HTML, data can be easily accessed, however, JavaScript does not have the same

When trying to access the 'data' element in a JSON object, I have encountered an issue. The element is accessible when called from HTML, but not when called in JavaScript. HTML: <p>{{geoJson.data}}</p> JavaScript: let scope; let d ...

Is it possible to return a promise within the .then function in AngularJS?

I have a unique service called "usersService". I want to create a special method that interacts with another custom service I built. This other service has two handy methods: getUser() and getCurrentUser(). The getCurrentUser() method relies on the injecte ...

The UI-router activates the child state prior to resolving the parent state

Currently, I am encountering an issue with executing initialization code within a parent state of the Angular ui-router. The initialization code in question is orderService.getStoreInfo(), which returns a promise. My intention is to trigger the child state ...

Why does AngularJS $watch only execute once?

Why do the codes in the watch only run once? How can I address this issue? this.$rootScope.$watch('tabType', () => { if (this.$rootScope["tabType"] === TabType.Sent) { this.$scope.refreshSentList(); } else if (this.$rootScope[ ...

Having trouble parsing JSON data from $_POST while utilizing AngularJS

While working in Angular, I encountered the following scenario: var data = {}; data['name'] = "test"; data['class'] = "testClass"; $http.post('http://testURL',data,function(data){ console.log(data); }); Upon inspecting the ...

Having trouble passing $scope, $route, or $http in your AngularJS factory functions?

Why does my factory keep throwing an error when the $scope, $route, $http are present? app.factory("factoryContacts",function($scope,$route,$http){ return { getContacts: function(){ return $http({ me ...

Choose the current parent item using Angular's ng-selected and $index

http://plnkr.co/edit/fwwAd4bn6z2vxVN2FUL7?p=preview On the Plunker page linked above, I am trying to achieve a specific functionality. I would like the 3 dropdown lists to display values A, B, and C initially. When a 4th dropdown option is added, it shoul ...

Traversing through nested arrays within nested objects using AngularJS

In my project, I am utilizing angularjs 1 and dealing with a complex json object that has multiple levels of nesting. My goal is to use ng-repeat in order to access a nested array within the json structure. [{ "information": { "name": "simdi jinki ...

Leveraging NodeJS functions within an HTML environment

After successfully creating a NodeJS back-end, I encountered a challenge. How can I connect my back-end to my front-end HTML/CSS page and utilize my NodeJS functions as scripts? ...

What are the steps to activate the hot-swapping feature for HTML and JavaScript files in IntelliJ's Community edition?

Just starting out with IntelliJ to work on an AngularJS project with spring-boot as the backend server. Every time I make changes to my HTML or JavaScript code, I find myself needing to restart the app server. Is there a configuration setting or plugin ava ...

Retrieve the controller function in AngularJS and then pass it as an argument to $injector.invoke() for execution

Initially, I had set up two controllers in the following way: function ControllerA(DependencyA, DependencyB) { // code } function ControllerB(DependencyC, DependencyD) { // code $injector.invoke(ControllerA); } However, for minification purp ...

Numerous Kendo windows are layered on top of each other, yet the text divisions within them remain distinct

I am currently working on a project that involves laying out multiple Kendo windows in rows. Specifically, I need to display 4 windows in each row and have them shift left when closed. My framework of choice is Bootstrap 3. Everything works as expected w ...

Tips for dynamically creating column headings and table values using JSON arrays in AngularJS

On a web page, there are two radio buttons that produce different results: The first button shows Student Details and the corresponding JSON array is as follows : [{"Name":"A", "Class":"x", "Section":"abcd", "DOB": "XYZ"}, {"Name":"B", "Class":"x", "S ...

Keep the AngularJS view up-to-date through regular modifications

Is there a way to automatically update the view when changes occur from another computer without refreshing the entire page? I attempted setting an interval to call my API every ten seconds and clear the cache, but this approach requires reloading all da ...