I want to programmaticaly edit a particular row. FF works like charm, Chrome not at all. Why?!

I want to programmaticaly edit a particular row. FF works like charm, Chrome not at all. Why?!

edwardcedwardc Posts: 30Questions: 11Answers: 0

When a condition is met (NOT clicking/selecting the row) I want to edit the one and only row I got in a table. I tried with several selectors. On FF works like charm. On Chrome not. Any suggestions?

            if (condition) {
                editor_IG.edit( '#my_table tbody tr:eq(0)' );
            }

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    We'd need more information I'm afraid. I don't see any reason why the above wouldn't work in Chrome. Can you give me a link to the page showing the issue please?

    Allan

  • edwardcedwardc Posts: 30Questions: 11Answers: 0

    Apologies.
    It turned out that the problem was not Chrome. On Mozilla I had the problem also, but more rare then on Chrome. Therefore, being a problem that doesn't manifest all the time, I concluded it is related to the loading time of ajax functions we use to get data for some fields that use select2 .
    This supposition is confirmed by the fact that using the edit button works perfectly but I wanted to programmatically launch it at the document.ready so maybe the editor did not had the time to initialize it self.
    I tried to move the code in an initComplete handler but I've seen is deprecated and I did not identified the successor as described in the documentation.
    Using it as it is, did not worked. I placed a simple alert('We got this!') but it was never triggered.
    Any suggestion @allan on what to use instead of deprecated initComplete? (correct link )

    Another question if I may: Adding field options in php was a brilliant move as it save us the effort of writing tens of controllers. However, some of the select2 are using options that need several joins and several conditions. Any thought on upgrading the php query model of the field-options?

    P.S. I can PM the link and a user & password for the page but you also need some pictures step-by-step guide on how to replicate the problem as it require to create a new order and the interface is in romanian. Maybe through email?

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    I tried to move the code in an initComplete handler but I've seen is deprecated and I did not identified the successor as described in the documentation.

    The Editor initialisation is synchronous so there is no need for an event. Indeed, by the time you've been able to attach it, it would already have fired!

    Perhaps the issue is coming from DataTables' initialisation? Are you ajax loading data for the DataTable? If so, then use initComplete in DataTables or its init event:

    var editor = new $.fn.dataTable.Editor( ... );
    var table = $(...)
      .on( 'init.dt', function () {
        editor.edit( ... );
      } )
      .DataTable( {
        ajax: ....,
        ...
      } );
    

    However, some of the select2 are using options that need several joins and several conditions.

    There isn't an option for the Options method to make use of a join yet, but I wrote it as a class so that it can be extended with those options in future. Instead, at the moment what you would need to do is use the option of defining a custom function to get the options. That function would make the required call to the database to get the options.

    If you want to use the same database interface that Editor's PHP files do, that is defined here.

    Regards,
    Allan

  • edwardcedwardc Posts: 30Questions: 11Answers: 0

    The Editor initialisation is synchronous so there is no need for an event.

    That make sense. It's clear now.

    Indeed the problem was with the datatable initialization. As soon as I moved in the initComplete event handler, worked like charm.

    Will test the custom functions as well, later on. So far I'm happy I sort this out.

This discussion has been closed.