Two questions really ..

Two questions really ..

jonrjonr Posts: 51Questions: 5Answers: 0

a) I would like to be able to send back from code-behind a class for each column/field that is on my table to indicate whether the user can amend or not an input field. I am thinking a class "data_field_enabled" or "date_field_disabled". Then my inline edit could skip fields where edit is disabled.

b) I am not sure whether DataTables are able to write back data to my SQL table automatically the changes entered by the user.
I think that perhaps that is a pretty tall order, I think I would prefer to be able to grab the return dataset and update the underlying tables myself. Is this by design?

jON

Answers

  • jonrjonr Posts: 51Questions: 5Answers: 0

    I have just realised that my datatable, inside a modal dialog is not actually being destroyed but I can't find any example of how to close the datatable or destroy it.

    There is an old k/b article for version 1.9 that shows destroy methods.

    Once I can hook into and destroy/close the DataTable I expect that I can use the on('close',...) event to send data back to the server.

    does anyone have any example of closing/destoying and sending data back? I expect to use ajax as I did to fetch but I am looking for the raw data to send back.

    jON

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    You can use destroy() to destroy a DataTable and Editor also has its own destroy() method that can be used to clean up.

    Regarding your first question - you would need to create a model that would transmit that data to the client-side (presumably as JSON) so the client-side can be configured that way. That isn't something that Editor or DataTables offers out of the box I'm afraid.

    For the second - Editor will write to the database table directly on submit (submit()) if you are using the provided .NET libraries. If you aren't then how it gets written to the database up to yourself. The parameters Editor submits are documented here. It is designed to use the provided server-side libraries, but also to work with custom implementations as needed.

    Allan

  • jonrjonr Posts: 51Questions: 5Answers: 0

    Thanks for the feedback Allan.

    But is there an event I can hook into when the datatable is closed/destoyed.

    There isn't one mentioned in the docs as far as I can see.

    I will trigger the destroy on a button click from my modal dialog and then upload the data myself I think, there is some server side logic the be run.

    thanks again,

    jON

  • jonrjonr Posts: 51Questions: 5Answers: 0

    With regards the a) above I have changed my data feed so that the "id" of each row returns an indicator of the type of row I am working with.

    If its an area or volume type row then I prompt for length and width and possible depth but if its a unit I only want to allow entry to the quantity cell.

    I am bewildered with the DataTables structure as I seem to be able to go down to many levels but never seem to find a string or numeric property, everything seems to be arrays.

    At this level

    $("#actuals").DataTable().cell(1,1)
    

    I would expect to have a text property

    $("#actuals").DataTable().cell(1,1).data()
    

    contains no data !?

    I want to check the ID of my table which is in the format of "01M3," "02M2", "03M" and if its an area the enable length and width and disable depth, if an "M" or a "Q" only enable the quantity cell.

    At the current time I can't even read any data, let alone start to work out how to hide/show a cell.

    can anyone please give me an example of code to just get to a data field and set to not visible?

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    But is there an event I can hook into when the datatable is closed/destoyed.

    destroy will be triggered when the table is destroyed. Note that simply removing it from the DOM will not destroy it. It would be valid to remove it from the DOM and add it back in in future.

    $("#actuals").DataTable().cell(1,1)

    This simply returns a DataTables reference to the cell in question. Think of it like $('#myId') in jQuery. Its the methods that you chain on to it that give you the ability to do something with it.

    $("#actuals").DataTable().cell(1,1).data()

    I'd need to be able to see the page to understand why it is saying no data there.

    can anyone please give me an example of code to just get to a data field and set to not visible?

    This shows how to get the data from a cell using cell().data(). I don't understand what you mean by then making it hidden. The cell?

    Allan

  • jonrjonr Posts: 51Questions: 5Answers: 0

    Calling the destroy() method doesn't seem to remove the table from the DOM, should it?

    Sorry Allan, I see that data() does return the contents of the cell. However, I really want to traverse all cells, or perhaps only cells from columns 2, 3 and 4.

    I was hoping to use something like this:

            var active = table
                .columns(function (idx, data, node) {
                    return $.inArray('Active', data) !== -1 ? true : false;
                })
                .data();
    

    to get the columns (2, 3 and 4) and then process the columns cells, hoping to find a function that would return "Active" or not depending on the type of row. So thereby setting "active" rather than "Visible". I was referring to the article that talks about "toggling" the display of cells.

    jON

  • jonrjonr Posts: 51Questions: 5Answers: 0

    damn, I don't have access to the ID column so this ..

    $("#actuals").DataTable().nodes(0,0).data()
    

    returns me the first visible cell on the table so attaching a code to each ID doesn't seem to be a good idea.

    Is the ID column available or not rendered Allan?

    jON

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Calling the destroy() method doesn't seem to remove the table from the DOM, should it?

    If you were to pass in true to the method, yes. The documentation for it is here: destroy().

    Sorry Allan, I see that data() does return the contents of the cell. However, I really want to traverse all cells, or perhaps only cells from columns 2, 3 and 4.

    Data from column index 2: table.column( 2 ).data()

    Data from columns indexes 2, 3 and 4 all together: table.columns( [2,3,4] ).data()

    to get the columns (2, 3 and 4) and then process the columns cells, hoping to find a function that would return "Active" or not depending on the type of row.

    You probably want to use rows() if you want to select rows based on the data in them, rather than columns in that case.

    I was referring to the article that talks about "toggling" the display of cells.

    Could you give me a link to that article? If it was one I wrote sorry - I've lost track of everything I've written over the last decade :smile:.

    Is the ID column available or not rendered Allan?

    Have you configured the first column to show the id?

    Allan

  • jonrjonr Posts: 51Questions: 5Answers: 0

    The article relating to toggling is

    https://datatables.net/reference/api/columns()

    I have been working my way up and down the cells() columns() and column selector documentation.

    The ID is defined using the property idSrc as 'ID'

    This field is not displayed on the table but I am sending back attached to the ID an indicator of row type.

    if idSrc is available as a column() then I can use it otherwise I will have to think of another way to send back row type. I do not currently display the ID (idSrc) field, I didn't know I could but I don't really want it to show.

    jON

This discussion has been closed.