jQWidgets Forums

jQuery UI Widgets Forums Grid one change in dropdownlist in grid is called multiple times

This topic contains 2 replies, has 2 voices, and was last updated by  elessar 10 years, 12 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • elessar
    Participant

    so, my jqxgrid is created like this:

     $("#jqxgrid").jqxGrid({
        
         source: source,
         theme: theme,
         selectionmode: 'checkbox',
         editmode: 'click',
         autowidth: false,
         autoheight: true,
         editable: true,
         sortable: true,
         columns: [{
             text: 'Node',
             datafield: 'title',
             editable: false,
             width: '31%'
         }, {
             text: 'Streams',
             datafield: 'datastreams',
             width: '39%',
             columntype: 'dropdownlist',
             initeditor: function(row, value, editor) {
                 var data = $('#jqxgrid').jqxGrid('getrowdata', row);
                 var dddatastreams = [];
               
               //here I create data for dropdownlist, because they can be different each time. 
                 for (var d in myApp.myArray[data.ID].array) {
                     dddatastreams.push(myApp.myArray[data.ID].array[d].id);
                 }
    
    			//set dropdownlist for data created in previous step
                 editor.jqxDropDownList({
                     source: dddatastreams,
                     checkboxes: true
                 });
               //create listener for the dropdownlist 
                 editor.on('checkChange', function(event) {
                     if (event.args) {
                         console.log("this log with same event is called as many times as editor was initiated");
                     }
                 });
             }
         }]
     });

    My problem is described in the comments in the code.

    So basically I need to initialize dropdownlist on each click in the cell. And I need to add listener to this dropdownlist.
    However this listener is called onChange as many times as the dropdownlist was initialized.

    For example : I just click on first row, then on second row, then on third row. Then I click again on the first row, choose one item from the dropdownlist, but the listener is called 4 times instead of one.

    I cannost use createeditor instead of initeditor, because the data of dropdownlist is different for each row. (And can change in time also)

    So can you please help me, how to modify my code, so the listener will be called just once?
    Thanks!


    Peter Stoev
    Keymaster

    Hi elessar,

    The issue in this code is that you bind to ‘checkChange’ each time the editor is opened. This should be done just once so I think that “createeditor” should be used for that purpose.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    elessar
    Participant

    thank you!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.