Column Search

Column Search

gutorockwellgutorockwell Posts: 2Questions: 1Answers: 0

Hello,

I would like to know hot to add an input search to search only for column ID where column is ID 1.

I'm using the following code

        $('.w-filter-right').prepend('<input type="text" id="min" class="form-control form-control-sm" placeholder="min">');
        var table = $('#task-table').DataTable();

        // #myInput is a <input type="text"> element
        $('#min').on( 'keyup', function () {
            table.columns( 1 ).search( this.value ).draw();
        } );

The full code that is in the project is the follow:

    $("#task-table").appTable({
        source: '<?php echo_uri("projects/my_tasks_list_data") ?>',
        serverSide: true,
        order: [[1, "desc"]],
        responsive: false, //hide responsive (+) icon
        filterDropdown: [
            {name: "specific_user_id", class: "w150", options: <?php echo $team_members_dropdown; ?>},
            {name: "milestone_id", class: "w150", options: [{id: "", text: "- <?php echo app_lang('milestone'); ?> -"}], dependency: ["project_id"], dataSource: '<?php echo_uri("projects/get_milestones_for_filter") ?>'}, //milestone is dependent on project
            {name: "priority_id", class: "w100", options: <?php echo $priorities_dropdown; ?>},
            {name: "project_id", class: "w200", options: <?php echo $projects_dropdown; ?>, dependent: ["milestone_id"]}, //reset milestone on changing of project
            {name: "quick_filter", class: "w200", showHtml: true, options: <?php echo view("projects/tasks/quick_filters_dropdown"); ?>}
            , <?php echo $custom_field_filters; ?>
        ],
        singleDatepicker: [{name: "deadline", defaultText: "<?php echo app_lang('deadline') ?>",
                options: [
                    {value: "expired", text: "<?php echo app_lang('expired') ?>"},
                    {value: moment().format("YYYY-MM-DD"), text: "<?php echo app_lang('today') ?>"},
                    {value: moment().add(1, 'days').format("YYYY-MM-DD"), text: "<?php echo app_lang('tomorrow') ?>"},
                    {value: moment().add(7, 'days').format("YYYY-MM-DD"), text: "<?php echo sprintf(app_lang('in_number_of_days'), 7); ?>"},
                    {value: moment().add(15, 'days').format("YYYY-MM-DD"), text: "<?php echo sprintf(app_lang('in_number_of_days'), 15); ?>"}
                ]}],
        multiSelect: [
            {
                name: "status_id",
                text: "<?php echo app_lang('status'); ?>",
                options: <?php echo json_encode($statuses); ?>
            }
        ],
        columns: [
            {visible: false, searchable: true},
            {title: '<?php echo app_lang("id") ?>', "class": idColumnClass, order_by: "id"},
            {title: '<?php echo app_lang("title") ?>', "class": titleColumnClass, order_by: "title"},
            {visible: false, searchable: true, order_by: "start_date"},
            {title: '<?php echo app_lang("start_date") ?>', "iDataSort": 3, visible: showOption, order_by: "start_date"},
            {visible: false, searchable: true, order_by: "deadline"},
            {title: '<?php echo app_lang("deadline") ?>', "iDataSort": 5, visible: showOption, order_by: "deadline"},
            {title: '<?php echo app_lang("milestone") ?>', visible: showOption, order_by: "milestone"},
            {title: '<?php echo app_lang("project") ?>', visible: showOption, order_by: "project"},
            {title: '<?php echo app_lang("assigned_to") ?>', "class": "min-w150", visible: showOption, order_by: "assigned_to"},
            {title: '<?php echo app_lang("collaborators") ?>', visible: showOption},
            {title: '<?php echo app_lang("status") ?>', visible: showOption, order_by: "status"}
            <?php echo $custom_field_headers; ?>,
            {visible: false, searchable: true}
        ],
        printColumns: combineCustomFieldsColumns([1, 2, 4, 6, 7, 8, 9, 10, 12], '<?php echo $custom_field_headers; ?>'),
        xlsColumns: combineCustomFieldsColumns([1, 2, 4, 6, 7, 8, 9, 10, 12], '<?php echo $custom_field_headers; ?>'),
        rowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
            $('td:eq(0)', nRow).attr("style", "border-left:5px solid " + aData[0] + " !important;");

            //add activated sub task filter class
            setTimeout(function () {
                var searchValue = $('#task-table').closest(".dataTables_wrapper").find("input[type=search]").val();
                if (searchValue.substring(0, 1) === "#") {
                    $('#task-table').find("[main-task-id='" + searchValue + "']").removeClass("filter-sub-task-button").addClass("remove-filter-button sub-task-filter-active");
                }
            }, 50);
        },
        onRelaodCallback: function () {
            hideBatchTasksBtn(true);
        },
        onInitComplete: function () {
            $('.w-filter-right').prepend('<input type="text" id="min" class="form-control form-control-sm" placeholder="min">');
            var table = $('#task-table').DataTable();

            // #myInput is a <input type="text"> element
            $('#min').on( 'keyup', function () {
                table.columns( 1 ).search( this.value ).draw();
            } );
        }
    });

Answers

  • allanallan Posts: 61,916Questions: 1Answers: 10,149 Site admin

    You are using server-side processing, so the first thing to check is if your PHP script ('<?php echo_uri("projects/my_tasks_list_data") ?>', ) supports the column filter parameters sent to it? What script are you using for that?

    Allan

  • gutorockwellgutorockwell Posts: 2Questions: 1Answers: 0

    Hello,

    I'm using the "Rise CRM" from codecanyon. how to check if it supports?

  • kthorngrenkthorngren Posts: 20,395Questions: 26Answers: 4,786

    I'm not sure what appTable is but if it includes Datatables, which it looks like it might, then you will need to check your server script to see if it supports the Server Side Parameters sent when using server side processing.

    Kevin

Sign In or Register to comment.