表格标题名称和复选框

如何解决表格标题名称和复选框

有人可以帮助我吗?我用复选框创建了一个表。但是我一直在丢失表标题名称,因为它已被复选框替换。带有复选框的第一列应该是“通知我”,另一列是“给我发送电子邮件”。如何将这些标题名称和复选框放在一起?这是我创建的代码:

<template>
    <Modal @close="doClose">
        <template v-slot:container>
            <section class="card settings-vue-modal-container">
                <header class="card-header">
                    <h2>Settings</h2>
                    <!-- <span class="custom-close fa fa-times" @click="doClose"></span> -->
                </header>
                <div class="card-body">
                    <div class='table-design'>
                        <SimpleDatatable
                            :init_data="tableData"
                            :init_columns="columns"
                            :init_is_loading="isTableLoading"
                            :isColumnCustomizable="false"
                            :isBoredered="true"
                            :isTableHeaderSticky="true"
                            :removeBorderWrapper="true"
                            :showTotalResult="false"
                            tableContentClass="users-table-content"
                            @changePage="changePage"
                            @getTableData="setTableData"
                            @getSelectedData="getSelectedData"
                        >
                        </SimpleDatatable>
                    </div>
                </div>
                <footer class="card-footer">
                    <div class="btn-group ml-auto float-right">
                        <button type="button" class="btn btn-secondary btn-close" @click="doClose">Close</button>
                    </div>
                </footer>
            </section>
        </template>
    </Modal>
</template>

<script>
import Modal from "../Reusable/Modal"
import SimpleDatatable from '../Others/SimpleDatatable';

export default {
    components: {
        Modal,SimpleDatatable
    },data() {
        return {
            settingsData: [],isTableLoading: false,params: {
                page: this.currentPage,page_limit: 10,search: '',role: ''
            },columns: [
                {
                    label: 'Task Schedule',field: 'name',align: 'center',default: true
                },{
                    label: 'Notify Me',type: 'checkbox',width: 200
                },{
                    label: 'Email Me',width: 200
                }
            ],tableData: {},currentPage: 1,selectedData: [],requiredData: {},errors: {},name: '',};
    },created() {
        this.getTableData()
    },watch: {
        currentPage(newValue,oldValue) {
            this.params.page = newValue
            this.getTableData()
        }
    },methods: {
        doClose() {
            this.errors = {};
            this.name = '';
            this.$emit('close');
        },changePage(event) {
            this.currentPage = event
        },setTableData(data) {
            this.tableData = data
        },getSelectedData(data) {
            this.selectedData = data.map(x => x.id)
        },getTableData() {
            this.isTableLoading = true
            let url = '/tasks/api/getAll'

            axios
                .post(url,this.params)
                .then(response => {
                    this.setTableData(response.data)
                    this.isTableLoading = false
                })
                .catch(errors => {
                    this.isTableLoading = false
                    console.log(errors)
                })
        },}
}
</script>

谢谢。下面也是正在使用的SimpleDatatable:

<template>
  <div class="row">
    <SeeMore
      :content="this.seeMoreContent"
      v-show="seeMoreModalVisibility"
      @close="seeMoreModalVisibility=false"
    />
    <div class="col-lg-12">
      <CustomizeColumnModal
        v-show="showColumnModal"
        @close="showColumnModal = false"
        :columns="init_columns"
        @getCols="getColumn"
      />
    </div>
    <div class="col-lg-12">
      <div
        class="panel panel-default"
        style="margin-bottom: 0"
        :class="{ 'no-border': removeBorderWrapper }"
      >
        <div
          class="panel-body"
          style="margin-bottom: 0"
          :class="{ 'no-border': removeBorderWrapper }"
        >
          <loading :active.sync="isLoading" :is-full-page="fullPage" style="z-index: 3;"></loading>
          <div class="pull-left">
            <slot name="functional_upper_left"></slot>
            <b
              class="ml-3"
              v-if="data.total && showTotalResult && totalResultPosition === 'upperLeft' "
            >Total Result: {{data.total | addComma }}</b>
          </div>
          <button
            class="btn btn-lg btn-primary pull-right"
            v-if="isColumnCustomizable"
            @click="showColumnModal = true"
            style="margin-bottom: 15px;"
          >
            <span class="fa fa-list" style=" margin-right: 5px;"></span> Columns
          </button>
          <slot name="functional_buttons"></slot>
          <div class="table table-responsive" style="overflow: auto; max-height: 550px;">
            <table
              class="table table-hover table-striped"
              :class="{ 'table-bordered': isBoredered }"
              style="margin-bottom: 0"
            >
              <thead>
                <tr>
                  <th
                    v-for="(col,index) in columns"
                    :class="{'amzentrix-th-sticky' : isTableHeaderSticky,'with-select-dropdown': col.type === 'checkbox' && isSelectOptions }"
                    :key="index"
                    :style="{ minWidth: (col.width) ? `${col.width}px`: '100px',textAlign: (col.align) ? `${col.align}` : 'left' }"
                  >
                    <template v-if="col.type === 'checkbox'">
                      <div class="dropdown">
                        <input type="checkbox" @click="doSelectAll" v-model="isSelectAll" />
                        <a
                          class="dropdown-toggle"
                          id="dropdownSelectOptions"
                          data-toggle="dropdown"
                          aria-haspopup="true"
                          aria-expanded="false"
                          v-if="isSelectOptions"
                        />
                        <div class="dropdown-menu" aria-labelledby="dropdownSelectOptions">
                          <span class="dropdown-item" @click="doSelectAllOnly">Select All</span>
                          <span class="dropdown-item" @click="doSelectTop(10)">Select Top 10</span>
                          <span class="dropdown-item" @click="doSelectTop(20)">Select Top 20</span>
                        </div>
                      </div>
                    </template>
                    <template v-else-if="col.sortable">
                      <div class="sortable_col" @click="sortCol(index)">
                        <span>{{ col.label }}</span>
                        <span class="sortable_icons">
                          <i class="fa fa-sort-up" :class="{ active: col.currentSort === 'ASC'}" />
                          <i
                            class="fa fa-sort-down"
                            :class="{ active: col.currentSort === 'DESC'}"
                          />
                        </span>
                      </div>
                    </template>
                    <template v-else>{{ col.label }}</template>
                  </th>
                </tr>
              </thead>
              <tbody v-if="data.total !== 0">
                <template v-for="(row,index) in data.data">
                  <tr :key="index">
                    <td
                      v-for="(col,index) in columns"
                      :class="tableContentClass"
                      :style="{
                                                textAlign: (col.align) ? `${col.align}` : 'left','vertical-align': (col.valign) ? col.valign : 'middle' 
                                            }"
                      :key="index"
                    >
                      <template v-if="col.type == 'checkbox' ">
                        <div class="vue-checkbox">
                          <input
                            type="checkbox"
                            :checked="row.selected"
                            @click="doSelect(row,$event)"
                          />
                        </div>
                      </template>
                      <template v-else-if="col.type === 'action'">
                        <slot :name="`action-${row.id}`">
                          <slot name="action" :data="row" />
                        </slot>
                      </template>
                      <template v-else-if="col.type == 'date'">{{ timeHumanize(row[col.field]) }}</template>
                      <template
                        v-else-if="col.type == 'complete_date'"
                      >{{ completeDateFormat(row[col.field]) }}</template>
                      <template v-else-if="col.type == 'raw'">
                        <div v-html="row[col.field]"></div>
                      </template>
                      <template v-else-if="col.type == 'rounded_numbers'">
                        <div>{{ row[col.field] ? Number(row[col.field]).toFixed(4) : row[col.field] }}</div>
                      </template>
                      <template
                        v-else-if="col.type == 'status'"
                      >{{ row[col.field] ? 'Active': 'Inactive' }}</template>
                      <template v-else-if="col.type == 'more'">
                        <div v-if="row[col.field]">
                          <p v-html="seeMoreTexts(row[col.field].replace(/<\/?[^>]+(>|$)/g,''))"></p>
                          <small
                            class="see-more"
                            @click="seeMore(row[col.field])"
                            v-if="row[col.field].length> 20"
                          >See More</small>
                        </div>
                        <p v-else>-</p>
                        <!-- {{ row[col.field] ? '<h1>awit</h1>' : '-' }} -->
                      </template>
                      <template v-else-if="col.type == 'field_value'">
                        <slot name="field_value" :data="row"></slot>
                      </template>
                      <template v-else>{{ row[col.field] ? row[col.field] : '-' }}</template>
                    </td>
                  </tr>
                </template>
              </tbody>
              <tbody v-else>
                <tr>
                  <td align="center" colspan="1000">
                    <slot name="no-result">
                      <span style="margin-right: 5px">No Data Found.</span>
                    </slot>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>

          <!-- PAGINATION -->
          <nav v-if="data.total && data.total !== 0 && !data.single">
            <ul class="pagination" :class="`float-${paginationPosition}`">
              <li
                class="page-item pagination-total-result px-3"
                v-if="data.total && showTotalResult && totalResultPosition === 'bottomPaginationLeftSide'"
              >
                Total Result:
                <b class="ml-2">{{data.total | addComma }}</b>
              </li>
              <slot name="pagination-left" />
              <li class="page-item pr-3 page-limit-select" v-if="isCustomResultPerPage">
                <label for="results-per-page">Results per page:</label>
                <input
                  class="form-control"
                  id="results-per-page"
                  type="number"
                  min="1"
                  @change="handleChangeItemsPerPage"
                  v-model="page_limit"
                />
              </li>
              <li
                class="page-item"
                :class=" data.current_page <= 1 ? 'disabled' : '' "
                @click=" changePage((data.current_page - 1))"
              >
                <a
                  class="page-link"
                  :href=" (data.current_page > 1) ? `#page-${data.current_page - 1}` : `#page-1`"
                  aria-label="Previous"
                >
                  <span aria-hidden="true">&laquo;</span>
                  <span class="sr-only">Previous</span>
                </a>
              </li>
              <li
                class="page-item"
                v-for="(n,index) in pagination(data.current_page,data.last_page)"
                :class="(n === data.current_page) ? 'active' : ''"
                :key="index"
                @click="changePage(n)"
              >
                <a class="page-link" :href="(typeof n == 'number') ? `#page-${n}` : '#' ">{{ n }}</a>
              </li>
              <li
                class="page-item"
                :class=" data.current_page >= data.last_page ? 'disabled' : '' "
                @click=" changePage((data.current_page + 1))"
              >
                <a
                  class="page-link"
                  :href=" (data.current_page < data.last_page) ? `#page-${data.current_page + 1}` : `#page-${data.last_page}`"
                  aria-label="Next"
                >
                  <span aria-hidden="true">&raquo;</span>
                  <span class="sr-only">Next</span>
                </a>
              </li>
              <slot name="pagination-right" />
            </ul>
          </nav>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped src='bootstrap/dist/css/bootstrap.min.css'></style>
<script>
import moment from "moment";
import CustomizeColumnModal from "./Datatable/CustomizeColumn";
import SeeMore from "./SimpleDatatableModal";
export default {
  components: {
    CustomizeColumnModal,SeeMore
  },props: {
    init_data: {
      type: Object,required: true
    },init_columns: {
      type: Array,init_is_loading: {
      type: Boolean,default: false
    },init_page_limit: {
      type: Number,default: 0
    },isSelectOptions: {
      type: Boolean,isColumnCustomizable: {
      type: Boolean,isBoredered: {
      type: Boolean,isTableHeaderSticky: {
      type: Boolean,isCustomResultPerPage: {
      type: Boolean,removeBorderWrapper: {
      type: Boolean,showTotalResult: {
      type: Boolean,totalResultPosition: {
      type: String,default: "upperLeft"
    },tableContentClass: {
      type: String,default: ""
    },paginationPosition: {
      type: String,default: "left"
    }
  },data() {
    return {
      data: { total: 0 },columns: this.init_columns,isLoading: this.init_is_loading,fullPage: false,isSelectAll: false,showColumnModal: false,seeMoreContent: "",seeMoreModalVisibility: false,page_limit: this.init_page_limit
    };
  },watch: {
    init_data(newData,oldData) {
      this.data = newData;
      this.isSelectAll = false;
      if (this.isSelectOptions) {
        this.getSelectedData();
      }
    },init_is_loading(newData,oldData) {
      this.isLoading = newData;
      if (this.isSelectOptions) {
        this.checkSelectHeaderModel(); //Will reset isSelectAll State. Important if you're using checkbox and with dynamic data.
      }
    },init_columns(newCols) {
      this.columns = newCols;
    },init_page_limit(newData) {
      this.page_limit = newData;
    }
  },filters: {
    addComma(value) {
      return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
    }
  },methods: {
    resetSortColFields() {
      const withSortColFields = this.columns.filter(col => col.currentSort);
      const resetColFields = withSortColFields.map(col => {
        col.currentSort = null;
        return col;
      });
    },//returns an object with sortType (eg. ASC or DESC ) and field (eg. DATE,ID)
    sortCol(index) {
      const { currentSort } = this.columns[index];
      let sort = null;

      this.resetSortColFields();

      switch (currentSort) {
        case "ASC":
          sort = null;
          break;
        case "DESC":
          sort = "ASC";
          break;
        default:
          sort = "DESC";
      }

      this.columns[index].currentSort = sort;

      this.$emit("sort",{
        sortType: sort,field: sort ? this.columns[index].field : null
      });
    },doSelectAll(event) {
      //single property for single set of data,means no paginated data.
      //usually you want to use this if you're not using primarily the api of laravel's pagination.
      //you just need to pass an initial object data with data and single properties
      if (!this.data.total && !this.data.single) {
        event.preventDefault();
        return;
      }

      this.isSelectAll = !this.isSelectAll;
      this.data.data.forEach(element => {
        element.selected = this.isSelectAll;
      });
      if (!this.isSelectAll) this.$emit("getDeselectedData",this.data.data);
      this.$emit("getTableData",this.data);
      this.getSelectedData();
    },doSelectAllOnly() {
      if (!this.isSelectAll) this.doSelectAll();
    },doSelectTop(num) {
      this.data.data.forEach((element,index) => {
        if (num > index) element.selected = true;
      });
      this.getSelectedData();
    },checkSelectHeaderModel() {
      // to check if all data from the data is selected,if true,checkbox from header must be checked.
      if (!this.data.data) return;
      const newDataLength = this.data.data.length;
      const newSelectedDataLength = this.data.data.filter(data => data.selected)
        .length;
      this.isSelectAll =
        newDataLength && newDataLength === newSelectedDataLength ? true : false;
    },doSelect(row,event) {
      let checked = Boolean(row.selected);
      row.selected = !checked;
      if (!row.selected) {
        this.$emit("getDeselectedItem",row);
      }
      this.getSelectedData();
    },getSelectedData() {
      const selected = this.data.data.filter(el => el.selected);
      this.checkSelectHeaderModel();
      this.$emit("getSelectedData",selected);
    },getColumn(event) {
      if (this.isColumnCustomizable) {
        this.columns = event;
        this.$emit("getSelectedColumns",event);
      }
    },timeHumanize(date) {
      return moment(date).isValid() ? moment(date).fromNow() : date;
    },completeDateFormat(date) {
      return moment(date).isValid()
        ? moment(date).format("MMM Do YYYY h:mm:ss a")
        : date;
    },changePage(pageNumber) {
      this.handleChangeItemsPerPage();
      if (
        pageNumber > 0 &&
        pageNumber <= this.data.last_page &&
        typeof pageNumber == "number" &&
        this.data.current_page != pageNumber
      )
        this.$emit("changePage",pageNumber);
    },pagination(c,m) {
      let current = c,last = m,delta = 3,left = current - delta,right = current + delta + 1,range = [],rangeWithDots = [],l;

      for (let i = 1; i <= last; i++) {
        if (i == 1 || i == last || (i >= left && i < right)) {
          range.push(i);
        }
      }

      for (let i of range) {
        if (l) {
          if (i - l === 2) {
            rangeWithDots.push(l + 1);
          } else if (i - l !== 1) {
            rangeWithDots.push("...");
          }
        }
        rangeWithDots.push(i);
        l = i;
      }

      return rangeWithDots;
    },seeMoreTexts(text) {
      return text.length > 20 ? text.substring(0,40) + "..." : text;
    },seeMore(data) {
      this.seeMoreContent = data;
      this.seeMoreModalVisibility = true;
    },handleChangeItemsPerPage(event) {
      let value;
      let changePage = false;
      if (typeof event == "object") {
        value = parseInt(event.target.value);
        changePage = true;
      } else {
        value = parseInt(this.page_limit);
      }
      if (value <= 0 || typeof value != "number" || !value) {
        value = 10;
        this.page_limit = 10;
      }
      this.$emit("handleChangeItemsPerPage",parseInt(value),changePage);
    }
  },mounted() {
    //single property for single set of data,means no paginated data.
    //usually you want to use this if you're not using primarily the api of laravel's pagination.
    //you just need to pass an initial object data with data and single properties
    this.data =
      this.init_data.total || this.init_data.single
        ? this.init_data
        : { total: 0 };
  }
};
</script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res