Editor inline not working when field property "data" is function

Editor inline not working when field property "data" is function

daveslabdaveslab Posts: 40Questions: 14Answers: 0

Hello,

This is perhaps an edge case, but it seems that Editor 1.6 doesn't work anymore in inline mode if the data property of a field is a function. According to the docs, it seems that I should be able to do something like this:

//...
{ label: "Date Correspondance:",  
  name: "date_correspondance",
  type: 'datetime',
  data: function(data, type, set) {
    return Utils.formatDate(data.date_correspondance);
  },
  format: CONSTANTS.DATE_FORMAT,
  opts: {
    momentStrict: true
  }
}
//...

And that works just fine if I edit a table row in main display mode. But if then I try to edit a cell using inline, like so:

$('#correspondances').on('click', 'td', function() {
  editor.inline( this );
});

I get this error: Uncaught Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11.

I even tried to set editField as recommended in link of that error message, but it still didn't work. In looking at the source code of Datatables Editor, it seems that the function __dtFieldsFromIdx doesn't take into account the fact that a dataSrc can be a function. Am I missing something?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin
    Answer ✓

    You are absolutely correct. Editor is use the data property rather than the name property for the lookup here, which is why it is failing.

    I can't remember off the top of my head, but I'm certain that I changed that for a reason. I'll spin over my commit history and try to determine why I changed that.

    Will post back with what I find.

    Allan

  • daveslabdaveslab Posts: 40Questions: 14Answers: 0

    Ah, glad to know that I'm not going crazy :). Thanks for always responding so promptly to our questions!

  • bryscbrysc Posts: 2Questions: 0Answers: 0
    edited March 2017

    Hi @allan,

    Is there any update on this?

    I have also come up against the same issue. I thought to try to update the uncompressed editor script to get this to work, but it looks like the surface area of the necessary changes would be risky without knowing editor's internals better. Not to mention that any fix I could come up with would break when upgrading to later versions.

    Are there any plans to allow for providing custom functions for getting field data when using inline mode? Barring that, are there any known workarounds?

    Thanks.

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    Sorry, I haven't had a chance to look into this yet. I will do so as soon as possible.

    Are there any plans to allow for providing custom functions for getting field data when using inline mode?

    I'm not entirely sure what you mean I'm afraid. Do you mean that when you activate inline editing, a function should run to format the data into the form that will be edited? If so, I'm afraid that is not an ability Editor currently has, and I don't (yet) have any plans to implement that. Editor works on the data in the data source object, so the data should be present there as required, or if output formatting is required, the field type should do that.

    Allan

  • bryscbrysc Posts: 2Questions: 0Answers: 0

    Hi @Allan,

    Thanks for the reply. I basically had the same question as daveslab in the original post. Though in my case it's less about formatting the data and more about selecting it. My team's scenario is pretty convoluted (i.e. we have to work with a schema based on the entity-attribute-value model) and probably warrants a separate question entirely. In the meantime, the question as to whether fields.data supports functions is answered.

    Thanks again.

    Bryan

  • bsdzbsdz Posts: 17Questions: 6Answers: 0

    Hi

    I'm running into same issue with inline editing a field that has a fields.data set as a function. The check

    var __dtFieldsFromIdx = function ( dt, fields, idx )
    {
        ...
        var run = function ( field, dataSrc ) {
            if ( field.dataSrc() === dataSrc ) {
                ...
        };
    

    is where the issue seems to appear.

    Hopefully a fix is on the horizon :-)

    Blair

  • bsdzbsdz Posts: 17Questions: 6Answers: 0

    This patch seems to fix it for me:

    var __dtFieldsFromIdx = function ( dt, fields, idx )
    {
        ...
        var run = function ( field, dataSrc ) {
            if ( (typeof(field.dataSrc()) == "function" ?  field.name(): field.dataSrc()) === dataSrc ) {
                ...
        };
    

    Although, I'm pretty sure it's not the right way or very efficient.

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    That's not a bad option actually. I'm not sure it is the right way since data is a function there and the name might not relate to the data point from the data source, but it could certainly work if that was how your project was setup.

    Allan

  • daveslabdaveslab Posts: 40Questions: 14Answers: 0

    Hi Allan,

    Do you have any updates on this? It's not personally mission critical for the moment, but do you have any idea when you might be able to try a bug fix sometime in the next couple of months?

    Thanks!

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin
    Answer ✓

    Sorry for the delay in updating this thread! Editor 1.6.2, which was released yesterday, changes the lookup to check the data point against the field's name property rather than the data source.

    Allan

  • daveslabdaveslab Posts: 40Questions: 14Answers: 0

    Ah, great, thanks Allan!

  • Scott BowersScott Bowers Posts: 13Questions: 2Answers: 0

    I know this is an old thread, but I have a use case where I am using inline editing, some fields are "select" and the content of those depend on the content of the row. I cant seem to get the "data" as a function to populate those dropdown boxes. If I have data in the tables for them, they populate, but that always overrides the data return in the data function. If I remove that data from "options" then the dropdown has nothing even though the function returns data. The function performs correctly when debugging.

    {
                                name:"unitId",
                                type:"select",
                                data:dojo.hitch(this,function(data,type,set){
                                    return uniqIt(data.location,"unitId","unitNumber","cropId","crop");
                                })
      }
    
  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    You want to be setting options, rather than data - see the examples at the end of select

    Colin

  • Scott BowersScott Bowers Posts: 13Questions: 2Answers: 0

    Thank you colin, it doesn't appear that options can be a function that can return data based on values in the row unless I am missing something.

  • Scott BowersScott Bowers Posts: 13Questions: 2Answers: 0

    fixed it by using the dependent function on the field that has the value these dropdowns are dependent on. When the dropdown is clicked on the dependent function runs and updates the options in the dropdown boxes.

This discussion has been closed.