我的代码有什么问题?学习Bootstrap

时间:2016-10-30 12:16:45

标签: javascript twitter-bootstrap datatable

我是新手,仍然在学习它。我目前正在处理我自己的这个项目。我设法在不使用参数的情况下查看数据表。在我的项目中,我在第一个数据库中点击后,我有两个数据表,一个参数应该传递给第二个数据表(空)(sample an ID),它将加载数据。如果没有我的控制器中的参数并使用a.BookTransactionHdrID == 100中的特定值,它将加载。但这不是我想要发生的事情。有人有想法吗?。

enter image description here

JS CODE

function fnGetStudentBook(getId) {

    if (getId != 0 || getId != undefined || getId != "") {
        dtStudBook = $('#dtBook').DataTable({
            responsive: true,
            processing: true,
            info: true,
            retrieve: true,
            destroy: true,
            search: true,
            stateSave: true,
            lengthMenu: [[5, 10, 20, -1], [5, 10, 20, "All"]],
            ajax: {
                "url": "/LS/GetStudentBook",
                "data": function (d) {
                    d.BookTransactionDtlID = getId;
               }
            },
            columns:
    [
             { data: "BookId", title: "", visible: false, searchable: false },
              //{ data: "Barcode", title: "Barcode",  searchable: false },
            { data: "Author", title: "Author" }
  //   { data: "Title", title: "Title", sClass: "alignRight" },
  //   { data: "DatePublish", title: "Date Publish", sClass: "alignRight" },
  //   { data: "PlacePublish", title: "Place Publish" },
  //   { data: "NameOfPublisher", title: "Name Of Publisher"},
  //   { data: "ISBN", title: "ISBN"},
  //   { data: "BookTransactionDtlID", title: "", visible: false }
      ]
        });
    }
    else {
        //do nothing..
    }
}

CONTROLLER

public JsonResult GetStudentBook(int getId)
    {
       // int getId = Convert.ToInt32(Request.QueryString["getId"]);
        var Data = new List<object>();
        Data = (from a in db.BookTransactionDtls
                join b in db.Books on a.BookID equals b.BookID
                where a.BookTransactionTypeID == 3 && a.BookTransactionHdrID == getId
                select new
                {
                    BookId = a.BookID,
                    //Barcode = b.Barcode,
                    Author = b.Author
                    //Title = b.Title,
                    //DatePublish = b.DatePublished,
                    //PlacePublish = b.PlacePublished,
                    //NameOfPublisher = b.NameOfPublisher,
                    //ISBN = b.ISBN,
                    //BookTransactionDtlID = a.BookTransactionDtlID
                }).OrderBy(a => a.BookId).ToList<object>();
        return gf.DataTableAjaxHandlerClientSide(Data);
    }

HTML

<div class="col-lg-6">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <div class="row">
                <div class="col-lg-6">
                    <i class="fa fa-list fa-fw"></i>Book
                </div>
            </div>
        </div>
        <!-- /.panel-heading -->
        <div class="panel-body">
            <div class="dataTable_wrapper">
                <div class="col-lg-6">
                    <table class="table table-striped table-bordered table-hover table-responsive nowrap"
                        role="grid" style="width: 10%;" id="dtBook">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

传递参数的onclick代码

var getId = 0;
var dtStudBook = "";
var dtBorrowerName = $('#dtBorrowerName').DataTable({
    responsive: true,
    processing: true,
    info: true,
    search: true,
    stateSave: true,
    order: [[1, "desc"]],
    lengthMenu: [[5, 10, 20, -1], [5, 10, 20, "All"]],
    ajax: { "url": "/LS/GetBorrower" },
    columns:
        [
            { data: "BorrowerID", title: "", visible: false, searchable: false },
            { data: "IDNo", title: "ID Number" },
            { data: "Name", title: "Complete Name", sClass: "alignRight", width: " 100px" },
            { data: "BookTransactionHdrID", title: "BookTransactionHdrID", visible: false, searchable: false }
        ]
});



$('#dtBorrowerName tbody').on('click', 'tr', function (e) {
    getId = dtBorrowerName.row(this).data().BookTransactionHdrID;
    alert(getId);
    fnGetStudentBook(getId)
 });

1 个答案:

答案 0 :(得分:0)

你可以在params中像jqgrid一样使用这样的东西。

ajax

如果您熟悉 ajax: { "url": "/LS/GetStudentBook?getId=" + getId }, ,也是如此。在您的代码中,["Session"]类似于Session。

希望它有所帮助。欢呼声。