Fild Datatables

Fild Datatables

marianidiegomarianidiego Posts: 74Questions: 22Answers: 1

Link to test case:
https://admin.cleanlife.ch/new_orders_test.php (temporary link)

Debugger code (debug.datatables.net):
materialEditor.on( 'initEdit', function( e, show, row ) {
materialEditor.field("product").val(materialEditor.field("products_id").get());
})

Description of problem:
I insert a new line, clicking on "nuovo".
I choose, for example, the third product: "2 LAV [A0162LAVTN20] #374931304"
I press "Aggiungi" to insert a first row on the table.

At this point, I select the first line, and press on "Modifica".

The screen reopens, but "2 LAV [A0162LAVTN20] #374931304" is not selected.

How come? The code is right.

Where is the error?!?!

If you analyze, you can see that the class "selected" is put in, but then it is taken out. How can this be?

Answers

  • kthorngrenkthorngren Posts: 22,159Questions: 26Answers: 5,101

    Looks like a login is needed for your test case link.

    Kevin

  • marianidiegomarianidiego Posts: 74Questions: 22Answers: 1

    :s

    Sorry, I hadn't thought of that.
    Correct. Now you can try it.

  • allanallan Posts: 64,746Questions: 1Answers: 10,713 Site admin

    Many thanks for the link.

    Such an error normally comes from the value in the row not exactly matching the option's value. In this case, the data in your dataproducts array has a value property which is an integer, but when inspecting the data that is in the DataTable, I can see that product is a string:

    product: "374932430"
    

    Since "374932430" !== 374932430 the option isn't selected, and the row is unselected.

    To address this, they need to be made the same type. I'm not sure why the DataTable one is a string, apologies I've not had time to dig into that part - you could try using fields.getFormatter to convert a string to an int, which might do it, or where you generate dataproducts, just make value a string which would probably be the easiest option.

    Allan

  • rf1234rf1234 Posts: 3,143Questions: 92Answers: 433
    edited July 13

    I had similar issues when upgrading my database. Before the upgrade everything was loaded as a string - and I didn't have any issues. Then suddenly numeric values were loaded as numeric variables. That of course changed based on user language. For example 17,20 was loaded as a string and 17.2 was loaded as a numeric.

    It was an absolute nightmare. The solution was to explicitly stringify all database fetches. So I added this to my PDO configuration.

  • rf1234rf1234 Posts: 3,143Questions: 92Answers: 433
    edited July 13

    The above is from the definition of my own db handler. If you are using Editor you would need to adjust "config.php" accordingly.

    Here is my "config.php":

    $sql_details = array(
        "type" => "Mysql",     // Database type: "Mysql", "Postgres", "Sqlserver", "Sqlite" or "Oracle"
        "user" => "yourUser",          // Database user name
        "pass" => "yourPW",          // Database password
        "host" => "localhost", // Database host
        "port" => "",          // Database connection port (can be left empty for default)
        "db"   => "yourDB",          // Database name
        "dsn"  => "charset=utf8mb4",          // PHP DSN extra information. Set as `charset=utf8mb4` if you are using MySQL
        "pdoAttr" => array( PDO::ATTR_STRINGIFY_FETCHES => true )   // PHP PDO attributes array. See the PHP documentation for all options
    );
    
  • marianidiegomarianidiego Posts: 74Questions: 22Answers: 1

    was a studipa thing, and I can't tell you how much time I wasted on it.

    thank you very much. It was really the integer/string thing.

    Greetings

    Diego

  • marianidiegomarianidiego Posts: 74Questions: 22Answers: 1

    Now, what I wanted to do was to put an image.

    Selecting a product upload its image. How would you do this?
    Do you have examples of the code?

  • allanallan Posts: 64,746Questions: 1Answers: 10,713 Site admin
    edited July 14

    There isn't an example of exactly that I'm afraid, however it would be possible.

    You can use the .dt() method of the datatable field type and bind a selected / deselected listener, which would in turn call field().labelInfo() in which you could display the image.

    let myField = myEditor.field('myField');
    let innerTable = myField.dt();
    
    innerTable.on('select deselect', function () {
      let selected = innerTable.row({selected: true});
    
      if (selected.any()) {
        myField.labelInfo( selected.data().myImage );
      }
      else {
        myField.labelInfo( '' );
      }
    });
    

    I haven't tested it, but something along those lines will hopefully help get you started with it.

    Allan

  • marianidiegomarianidiego Posts: 74Questions: 22Answers: 1

    Hi Allan,

    I also tried labelInfo. Only this would go on top of the "search input".
    I would like to optimize the space by putting it below.

    Do you think that the only way?

Sign In or Register to comment.