update column for marked rows

update column for marked rows

tableFan22tableFan22 Posts: 8Questions: 2Answers: 0

Hello,

I have this editor table that works quite well. Now I want to set the marked rows, the column "checked" to true with a button for all marked ones. How can I do that?
(P.S. I have the license for the editor tables on my company account, this is my private account)
thanks

 public ActionResult EditorTable()
            {        
                string dbConnection = this._configuration.GetSection("ConnectionStrings")[connection];

                using (var db = new Database("azure", dbConnection))

                    {
                        var response = new Editor(db, "DBtable")
                            .Model<DBtable>()
                            .Field(new Field("Name"))
                            .Field(new Field("checked"))
                            .TryCatch(false)                    
                            .Process(Request)
                            .Data();
                        return Json(response);
                    }

            }

    <div class = "card">
        <div class = "card-header"></div>
        <div class = "card-body">
            <table id = "tableID" class="table">
                <thead>
                    <tr>
                        <th>
                            Name
                        </th>
                        <th></th>
                    </tr>
                </thead>
                <tfoot>
                    <tr></tr>
                </tfoot> 
            </table>
        </div>
        <div class = "card-footer"></div>
    </div>


    <script type="text/javascript">
            var editor; 
            $(document).ready(function(){
                editor = new $.fn.dataTable.Editor ({
                    ajax: {url: "/Controller/EditorTable" , type: "POST"},
                    table: "#tableID",
                    fields: [{
                        label: "Name",
                        name: "Name"          
                        }
                    ]
                });

                $('#tableID').on('click', 'tbody td:not(:first-child)', function (e) {
                    editor.inline(this);
                });

               var table = $('#tableID').DataTable({
                dom: "Bfrtip",
                lengthMenu: [
                   [10, 25, 50, -1],
                   ['10 rows', '25 rows', '50 rows', 'Show all']
                ],
                stateSave: true,
                ajax: "/Controller/EditorTable",

                columns: [
                    {
                        data: null,
                        defaultContent: '',
                        className: 'select-checkbox',
                        orderable: false
                    },
                    { data: "Name"}
                ],
                select: {
                    style: 'os',
                    selector: 'td:first-child'
                },
                buttons: [
                    { extend: "create", editor: editor },
                    { extend: "edit", editor: editor },
                    { extend: "remove", editor: editor },
                    'pageLength'
                ]
              });
          });
        </script>

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    This Select example shows how to create a Select All button.

    Kevin

  • tableFan22tableFan22 Posts: 8Questions: 2Answers: 0

    this is not what I want.. I want to be able to select some rows or all and when I click on a button, the button sets the column "cheked" to true for these rows. (update column)

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Sounds like you want a checkbox column that is not used for selecting the rows, is that correct? Maybe this Editor checkbox example is closer to what you want.

    Kevin

  • tableFan22tableFan22 Posts: 8Questions: 2Answers: 0

    The column checked is varchar, which means I have to write "true" in it and unfortunately that doesn't help me either, because I can't mark several lines and write true to all of them with button at the same time

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Maybe I still don't understand the requirement but you might be able to use the edit() and field().multiSet() APIs to achieve the result you need. See the example snippet in the field().multiSet() docs.

    If you still need help then please provide a simple test case with an example of what you have so we can offer more specific suggestions. You can start with this basic Editor test case:
    http://live.datatables.net/guwafemu/178/edit

    Kevin

Sign In or Register to comment.