Inplace editing of concatenated fields

Inplace editing of concatenated fields

justStevejustSteve Posts: 49Questions: 8Answers: 1
edited February 2010 in General
My backend has separate fields for 'FirstName' and 'LastName' but I concatenate the fields when I displaying them in a DataTables' cell. Any hope of finding an 'in-place' editing strategy?

thx

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Interesting question. I'm not sure how well I can answer it, but basically you need to have a 'separator' which you can use to break the string apart into it's components. A space is the most obvious, but it's valid to have a first name and a last name with one or more spaces in them - which would mess that up!

    One option might be to have two hidden fields (first and last names), as well as the visible one. Then for every key press, you can check the hidden fields, and see where the change was made, and how it should be altered. A little fiddly - but I've not got a better suggestion at the moment...

    Regards,
    Allan
  • justStevejustSteve Posts: 49Questions: 8Answers: 1
    thx for your thoughts...
    Seems everytime i start to implement any sort of edit in place mechanism i reach the conclusion that I'd be better off using a popup instead. I'm usually coding 'summary' rows as opposed to raw, tabular data. My example above is much more complex than just FirstName|LastName - some cells are calculated - most contain links or other embedded html and so on. Not a good candidate for in-place editing.

    So I'd like to refactor the UI - make a doubleclick on any given row bring up a container where cells _are mapped one-to-one to the db.

    So let me reframe my question:

    If each row of my DataTables contains complex fields as described above, and;
    I really, really need to let my boss edit the 'do not fire' field, and;
    I wanted a doubleclick event to open a jEditable version of that row ('open' meaning the same behavior as a subtable 'opens' [http://datatables.net/examples/api/row_details.html]) and;
    I knew the structure and framework of DataTables and how it interacts with jQuery inside and out - i mean i knew this code almost as well as if i had written it myself ...

    If the above where true, wouldn't it be trivial to code a function that builds the subtable while the main DataTables table is building? As each row is rendered this function renders (but not displays) a 'details' row where editable cells mapped to the db?

    and by 'trivial' i mean - worth a modest donation? it'd be kinda cool to see a new example on your page titled:
    'A Better Editor - sponsored by steve
    [/tongue in cheek]

    thx
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    haha - I love the idea of senior management sitting there with a web app going, "mawahaha" and double clicking the "do not fire" check box (can you tell I'm not senior management...).

    What I would be tempted to do in this case, would be to have the double click call fnOpen for the row as you say, and dispatch an Ajax call to the server to load the form. This would include the current information (separated in their forms, rather than concatenated etc), and just basically be an standard HTML form. Equally it would have a sumbit handler on it, that when called would submit the form to the database, and call fnUpdate with the result, to update the row. I think jEditable would probably add a little complication that isn't needed here, since you aren't editing in place (which is what jEditable does) rather you are specifically creating a form for exactly the input you desire.

    Another option, which doesn't involve loading an HTML form from the server, would be to have a rendering function for fnOpen which would read hidden information from the table (hidden columns) about individual database fields, and construct the form that way. Doesn't really matter which way you pick, end result is the same :-)

    How does that sound?

    Regards,
    Allan
This discussion has been closed.