manually set array for compound key

manually set array for compound key

rldean1rldean1 Posts: 141Questions: 66Answers: 1
edited June 2018 in Free community support

I'm not using Node.js, .NET, or PHP... But my baby has a sweet SQL backend.

I need to set a compound key in DT/Editor. From what I've gleaned, the compound key can be specified as an array with the contents of the primary key.

Where do I set the compound key -- Editor or DataTables?

DataTables has rowId() --- do I construct the array of keys there? If so, how?

OR --- would I use Editor's idSrc? Something like:
idSrc: "FicalStart + '_' + PaySchedule"

Basically, I assume I need to get the following JSON structure to Editor, and that I will need to deconstruct that structure when I'm in SQL:

"DT_RowId":{"FiscalStart":"2018-06-07","PaySchedule":"US-1"}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    The way that the Editor libraries do a compound key is to join on the server-side (in the .NET, PHP and Node libraries you specify the primary key as an array at the server-side).

    The client-side only ever sees a single value for the row id, so it doesn't do any concatenation itself. When the edit information is submitted the server-side then splits the data (it uses a mini hash of the ids as the field separator - but that's an implementation detail).

    Are you able to have your SQL backend do the concatenation?

    Allan

  • rldean1rldean1 Posts: 141Questions: 66Answers: 1

    @allan ,

    Yes, I could output a column that concats the columns that are part of the compound key FiscalStart_PaySchedule... I could name the column whatever: "id".

    Any recommendation for a delimiter?

    I then should reference this "constructed" column as the rowId and the idSrc?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Any recommendation for a delimiter?

    It its never going to change, use a simple colon or dash. It it might change, or you might change the order, then using a mini hash like the Editor libraries do would be the way to do (then decoding would fail if someone attempted to submit a value with the old hash).

    And yes, use rowId and idSrc as the new constructed value.

    Allan

This discussion has been closed.