View-model for datatable?

View-model for datatable?

lolskilolski Posts: 2Questions: 0Answers: 0
edited November 2013 in DataTables 1.9
Does Datatable have a view-model of some sort? E.g. so I can keep, let's say a number 1000000 and format it for display (e.g for displaying money) while keeping the integer representation intact so that when updated I don't have to convert back the money format to integer representation for example.

PS: storing money as integer is a bad move, but I just want to give a quick example

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    So some extent - it takes an 'orthogonal data' approach which is described in this blog post: http://datatables.net/blog/Orthogonal_data . mRender (which isn't mentioned in the blog post, since it was written before mRender was added, but is important to the discussion) is the compliment to mData . So mData is used to tell DataTables where to get the raw data, while mRender is used to format the data (adding currency information etc).

    DataTables 1.10 takes this orthogonal data approach a bit further in that you can use HTML 5 `data-*` attributes to specify the orthogonal data. So `data-order="1000000"` is used for sorting while the cell might contain `$1'000'000` as plain text.

    Regards,
    Allan
  • lolskilolski Posts: 2Questions: 0Answers: 0
    Thank you.

    I think I didn't make my intentions clear enough in my previous post. I am familiar with both mData and mRender and how to use them to format data input into a nice-looking ones for display.

    However, my real question is this: sometimes, I want to get the value within one of these cells into my "edit record" dialog box (lets say I don't want to use inline row editing). If I were to get these values directly from the cells, I'd get one that has been formatted by mData/mRender, not the raw ones I actually needed.

    To circumvent this, I would have to create a separate data model / or "View Model" to store these raw data, which would be fed and transformed into formated ones in the datatable by using mData or mRender.

    However, maintaining a separate model like this is enough hassle since you have to burden yourself with notifying the table whenever the data changes, as well as updating both the model and the datatable definition if I want to add/remove columns. So I'm wondering if there is already an internal model already present in datatable for such purpose.

    Regards,
This discussion has been closed.