Filling of DataTable programmatically with different field types

Filling of DataTable programmatically with different field types

Evgeniy VasylievEvgeniy Vasyliev Posts: 12Questions: 2Answers: 0

Hello everyone!

Maybe someone can help where it is possible to find any example on how to create a DataTable programmatically, where on the fly depending on external conditions we can add fields of different types, so the the Editor uses them for selection.

For example we get information that a table should contain 3 columns:
- select list (options provided)
- checkbox
- text

We need to generate a DataTable based on it and fill it with data, which are also taken from external data source.

I am trying to dig in API for this, however can not find any suitable page for explanation. Did you face any experience with it?

Thank you in advance!

This question has an accepted answers - jump to answer

Answers

  • Evgeniy VasylievEvgeniy Vasyliev Posts: 12Questions: 2Answers: 0

    Note please that questions is requested for JavaScript API only.

  • tangerinetangerine Posts: 2,099Questions: 14Answers: 232

    For example we get information that a table should contain 3 columns

    How do you receive the information?

  • Evgeniy VasylievEvgeniy Vasyliev Posts: 12Questions: 2Answers: 0

    Tangerine, thank you for response.

    I am using DatatTables in web server of MCU (ARM Cortex). There are lots of parameters to configure and they are described using a meta language in Json file. So, I am reading this file and getting data on what should be a field type and what data to fill it with. So, I need to build the DataTable accordingly.

  • kthorngrenkthorngren Posts: 2,970Questions: 19Answers: 669

    Datatables and Editor are initialized by passing parameters that are in a JS object, {}. Within the object are keys, such as fields for Editor or columns for Datatables. You can build these objects as JS variables which can be used in the parameters. This example shows one way to build dynamic columns for Datatables:

    http://live.datatables.net/regatofe/1/edit

    You can expand this to other parameters and Editor.

    Does this answer your questions?

    Kevin

  • Evgeniy VasylievEvgeniy Vasyliev Posts: 12Questions: 2Answers: 0

    Yes, Kevin! I was able to use your example successfully for one of the cases.

    However the question I am mostly interested in is a bit different: imagine that I am doing a properties configuration page on a server. All the properties are described in json file, the properties can be of the following types:
    - list of options
    - input value
    - checkbox

    So, I would like to use DataTables + Editor in order to solve this task.

    For example please watch on this image on how I am doing it in application for Windows: technotrade.ua/Uploads/Datatables/Parameters.jpg

    So, I want to find a solution to make the same using DataTables in a web server.

  • allanallan Posts: 47,070Questions: 1Answers: 6,629 Site admin
    Answer ✓

    Yes that is possible with Editor, but it won't read your database structure automatically. You'd need to read your configurated field information and then use the APIs of DataTables / Editor and the server-side libraries to built up the objects needed.

    Allan

  • Evgeniy VasylievEvgeniy Vasyliev Posts: 12Questions: 2Answers: 0

    Yes, Allan, exactly! Actually there is no database cause this is MCU, there is a separate API for communication, so I need to handle all the data processing locally using javascript.

    The question is: can you point any example on where can I find any useful example on how to modify the Editor depending on the field type, so that it can display different data, I mean something like:

    if (field.type === 'select') {
        // Prepare options list
    } else if (field.type === 'checkbox') {
        // Prepare checkbox
    } else if (field.type === 'text') {
        // Prepare text with possible mask
    }
    
  • allanallan Posts: 47,070Questions: 1Answers: 6,629 Site admin

    In Javascript you would use the add() method. Basically do your if logic from above, adding the required configuration for each field.

    In DataTables the columns can only be defined at initialisation time, so you need to build up a column array (columns) which can be used during the initialisation.

    Allan

Sign In or Register to comment.