File location

File location

hadarhadar Posts: 17Questions: 4Answers: 0

Hi,
Few questions:
1. I have table where one of the fields is file location.is it possible to have such column with browse option and when user select the file the value will be the location of the file?
2. Can I have column with specific values and when user edit the cell he will get list of options, for example column priority can get values:low,medium,high
3. Some of the columns are boolean, can it be shown as checkbox and if yes how it will be shown if I take table data to json or export to csv

Thanks

Answers

  • kthorngrenkthorngren Posts: 20,139Questions: 26Answers: 4,735
    edited May 2022
    1. One option might be to provide a clickable link. See the 4th example in the columns.render docs. Also take a look at this Data rendering example.
    2. You can create a select list using columns.render. Other than displaying the changed option are you saving the change to the DB?
    3. Not sure if you are using Editor but this example shows how to keep the checkbox state. Ignore the Editor portions if you aren't using Editor.

    Kevin

  • hadarhadar Posts: 17Questions: 4Answers: 0

    Thanks for your reply.

    regarding number 3.

    I add the checkbox but when export to CSV or get the data it always shown as TRUE regardless if the checkbox is checked or not.

    If I inspect the checkbox that what I see:
    <input type="checkbox" class="editor-active">

    regardless the checkbox is checked or not.

  • kthorngrenkthorngren Posts: 20,139Questions: 26Answers: 4,735

    I found an old checkbox example and updated it a bit to with Excel export. The exact steps you need to take will depend on how you are handling the checkboxes. You might need to use Orthogonal data like this export example.

    Take a look at this example:
    http://live.datatables.net/cubefaqa/25/edit

    The click event keeps the Datatables data cache updated with 0 or 1 depending on checkbox state. The export code in columns.render uses return data ? data : 0; because the initial data for the checkbox column is undefined. You may need to do something different.

    Kevin

  • hadarhadar Posts: 17Questions: 4Answers: 0
    edited May 2022

    Thanks for your reply,

    I create a test case in http://live.datatables.net/hamuxupe/1/edit so maybe the traget will be more clear

    for the demo the json contain the fields :
    Active (Boolean - checkbox)
    fieldString - should be editable to any String
    fieldSelect - can be one of : low,medium,high
    fieldBoolean - can be true or faslo
    fieldFile - location of file

    The data can be read from CSV file (for the example I enter some hard coded data)
    The user can edit the lines or add new line (delete also in futute)
    if Possible the user can use the file browse to enter valid file name

    the user can export the data in table to CSV and to import it,
    The user can get the table data as JSON (so I can take it as paramer for another operation)

    Can it be done ? (I hope the target is clear)

    (The server side that read CSV and return the JSON is working)

  • kthorngrenkthorngren Posts: 20,139Questions: 26Answers: 4,735

    The Editor has most all those features builtin. Like editing the rows and CSV import. It is possible to write your own code for these features.

    The Data docs describe the supported data formats. You can fetch JSON data via jQuery ajax() and populate the Datatable with the response.

    Take a look at the API docs for things like row().data() and cell().data() to both get and set the table data. You will see the use of cell().data() to both get the checkbox cell data and to update the data in the example I provided.

    Kevin

Sign In or Register to comment.